MCPcopy
hub / github.com/sveltejs/svelte / set

Method set

packages/svelte/src/motion/spring.js:298–323  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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);

Callers 2

ofMethod · 0.95
targetMethod · 0.95

Calls 4

#updateMethod · 0.95
setFunction · 0.90
deferredFunction · 0.90
abortMethod · 0.80

Tested by

no test coverage detected