* @param {number} type * @param {null | (() => void | (() => void))} fn * @returns {Effect}
(type, fn)
| 84 | * @returns {Effect} |
| 85 | */ |
| 86 | function 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 |
no test coverage detected