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

Function create_effect

packages/svelte/src/internal/client/reactivity/effects.js:86–179  ·  view source on GitHub ↗

* @param {number} type * @param {null | (() => void | (() => void))} fn * @returns {Effect}

(type, fn)

Source from the content-addressed store, hash-verified

84 * @returns {Effect}
85 */
86function create_effect(type, fn) {
87 var parent = active_effect;
88
89 if (DEV) {
90 // Ensure the parent is never an inspect effect
91 while (parent !== null && (parent.f & EAGER_EFFECT) !== 0) {
92 parent = parent.parent;
93 }
94 }
95
96 if (parent !== null && (parent.f & INERT) !== 0) {
97 type |= INERT;
98 }
99
100 /** @type {Effect} */
101 var effect = {
102 ctx: component_context,
103 deps: null,
104 nodes: null,
105 f: type | DIRTY | CONNECTED,
106 first: null,
107 fn,
108 last: null,
109 next: null,
110 parent,
111 b: parent && parent.b,
112 prev: null,
113 teardown: null,
114 wv: 0,
115 ac: null
116 };
117
118 if (DEV) {
119 effect.component_function = dev_current_component_function;
120 }
121
122 current_batch?.register_created_effect(effect);
123
124 /** @type {Effect | null} */
125 var e = effect;
126
127 if ((type & EFFECT) !== 0) {
128 if (collected_effects !== null) {
129 // created during traversal — collect and run afterwards
130 collected_effects.push(effect);
131 } else {
132 // schedule for later
133 Batch.ensure().schedule(effect);
134 }
135 } else if (fn !== null) {
136 try {
137 update_effect(effect);
138 } catch (e) {
139 destroy_effect(effect);
140 throw e;
141 }
142
143 // if an effect doesn't need to be kept in the tree (because it

Callers 14

teardownFunction · 0.85
create_user_effectFunction · 0.85
user_pre_effectFunction · 0.85
eager_effectFunction · 0.85
effect_rootFunction · 0.85
component_rootFunction · 0.85
effectFunction · 0.85
async_effectFunction · 0.85
render_effectFunction · 0.85
template_effectFunction · 0.85
deferred_template_effectFunction · 0.85
blockFunction · 0.85

Calls 7

update_effectFunction · 0.90
destroy_effectFunction · 0.85
push_effectFunction · 0.85
pushMethod · 0.80
scheduleMethod · 0.80
ensureMethod · 0.45

Tested by

no test coverage detected