* Sets `spring.target` to `value` and returns a `Promise` that resolves if and when `spring.current` catches up to it. * * If `options.instant` is `true`, `spring.current` immediately matches `spring.target`. * * If `options.preserveMomentum` is provided, the spring will continue on its curr
(value, options)
| 296 | * @param {SpringUpdateOptions} [options] |
| 297 | */ |
| 298 | set(value, options) { |
| 299 | this.#deferred?.reject(new Error('Aborted')); |
| 300 | |
| 301 | if (options?.instant || this.#current.v === undefined) { |
| 302 | this.#task?.abort(); |
| 303 | this.#task = null; |
| 304 | set(this.#current, set(this.#target, value)); |
| 305 | this.#last_value = value; |
| 306 | return Promise.resolve(); |
| 307 | } |
| 308 | |
| 309 | if (options?.preserveMomentum) { |
| 310 | this.#inverse_mass = 0; |
| 311 | this.#momentum = options.preserveMomentum; |
| 312 | } |
| 313 | |
| 314 | var d = (this.#deferred = deferred()); |
| 315 | d.promise.catch(noop); |
| 316 | |
| 317 | this.#update(value).then(() => { |
| 318 | if (d !== this.#deferred) return; |
| 319 | d.resolve(undefined); |
| 320 | }); |
| 321 | |
| 322 | return d.promise; |
| 323 | } |
| 324 | |
| 325 | get current() { |
| 326 | return get(this.#current); |