@lightningjs/blits
Advanced tools
Comparing version 1.6.1 to 1.7.0
# Changelog | ||
## v1.6.0 | ||
## v1.7.0 | ||
_14 oct 2024_ | ||
- Added cleanup upon component destroy of effects generated by global reactivity | ||
## v1.6.0 / v1.6.1 | ||
_9 oct 2024_ | ||
@@ -6,0 +12,0 @@ |
{ | ||
"name": "@lightningjs/blits", | ||
"version": "1.6.1", | ||
"version": "1.7.0", | ||
"description": "Blits: The Lightning 3 App Development Framework", | ||
@@ -5,0 +5,0 @@ "bin": "bin/index.js", |
@@ -164,5 +164,8 @@ /* | ||
for (let i = 0; i < effects.length; i++) { | ||
effect(() => { | ||
const eff = () => { | ||
effects[i](this, this[symbols.children], config, globalComponents, rootComponent, effect) | ||
}) | ||
} | ||
// store reference to the effect | ||
this[symbols.effects].push(eff) | ||
effect(eff) | ||
} | ||
@@ -169,0 +172,0 @@ |
@@ -23,2 +23,3 @@ /* | ||
import { Log } from '../../lib/log.js' | ||
import { removeGlobalEffects } from '../../lib/reactivity/effect.js' | ||
@@ -60,2 +61,3 @@ export default { | ||
deleteChildren(this[symbols.children]) | ||
removeGlobalEffects(this[symbols.effects]) | ||
Log.debug(`Destroyed component ${this.componentId}`) | ||
@@ -62,0 +64,0 @@ }, |
@@ -35,2 +35,4 @@ /* | ||
component[symbols.effects] = [] | ||
// setup hooks | ||
@@ -37,0 +39,0 @@ registerHooks(config.hooks, component[symbols.identifier]) |
@@ -395,9 +395,11 @@ /* | ||
// inner scope variables are part of the main forloop | ||
innerScopeEffects.forEach((effect) => { | ||
innerScopeEffects.forEach((effect, index) => { | ||
const key = effect.indexOf(`scope.${index}`) > -1 ? `'${interpolate(result[2], '')}'` : null | ||
if (effect.indexOf("Symbol.for('props')") === -1) { | ||
ctx.renderCode.push(` | ||
effect(() => { | ||
let eff${index} = () => { | ||
${effect} | ||
}, ${key}) | ||
} | ||
effect(eff${index}, ${key}) | ||
component[Symbol.for('effects')].push(eff${index}) | ||
`) | ||
@@ -404,0 +406,0 @@ } else { |
@@ -32,4 +32,18 @@ /* | ||
const objectMap = new WeakMap() | ||
const globalEffectsMap = new Map() | ||
export const track = (target, key) => { | ||
export const removeGlobalEffects = (effectsToRemove) => { | ||
if (globalEffectsMap.size === 0) return | ||
for (const [effect, target] of globalEffectsMap) { | ||
if (effectsToRemove.indexOf(effect) === -1) continue | ||
const effectsSet = objectMap.get(target) | ||
if (effectsSet === undefined) continue | ||
for (const set of effectsSet.values()) { | ||
set.delete(effect) | ||
globalEffectsMap.delete(effect) | ||
} | ||
} | ||
} | ||
export const track = (target, key, global = false) => { | ||
if (currentEffect) { | ||
@@ -53,2 +67,4 @@ if (paused) { | ||
effects.add(currentEffect) | ||
if (global === true) globalEffectsMap.set(currentEffect, target) | ||
} | ||
@@ -55,0 +71,0 @@ } |
@@ -31,3 +31,3 @@ /* | ||
const reactiveProxy = (original, _parent = null, _key) => { | ||
const reactiveProxy = (original, _parent = null, _key, global) => { | ||
// don't create a proxy when a Blits component or an Image Texture | ||
@@ -57,3 +57,3 @@ // is assigned to a state variable | ||
if (Array.isArray(target[key])) { | ||
track(target, key) | ||
track(target, key, global) | ||
} | ||
@@ -86,3 +86,3 @@ // create a new reactive proxy | ||
if (Array.isArray(target[key])) { | ||
track(target, key) | ||
track(target, key, global) | ||
} | ||
@@ -95,3 +95,3 @@ // create a new reactive proxy | ||
// track the key on the target | ||
track(target, key) | ||
track(target, key, global) | ||
// return the reflected value | ||
@@ -126,3 +126,3 @@ return Reflect.get(target, key, receiver) | ||
const reactiveDefineProperty = (target) => { | ||
const reactiveDefineProperty = (target, global) => { | ||
Object.keys(target).forEach((key) => { | ||
@@ -148,3 +148,3 @@ let internalValue = target[key] | ||
get() { | ||
track(target, key) | ||
track(target, key, global) | ||
return internalValue | ||
@@ -166,4 +166,6 @@ }, | ||
export const reactive = (target, mode = 'Proxy') => { | ||
return mode === 'defineProperty' ? reactiveDefineProperty(target) : reactiveProxy(target) | ||
export const reactive = (target, mode = 'Proxy', global = false) => { | ||
return mode === 'defineProperty' | ||
? reactiveDefineProperty(target, global) | ||
: reactiveProxy(target, undefined, undefined, global) | ||
} | ||
@@ -170,0 +172,0 @@ |
@@ -49,2 +49,4 @@ export default { | ||
isComponent: Symbol.for('isComponent'), | ||
// Symbol 'effects' utilized within generated code | ||
effects: Symbol.for('effects'), | ||
} |
@@ -24,4 +24,4 @@ /* | ||
plugin(state = {}) { | ||
return reactive(state, Settings.get('reactivityMode')) | ||
return reactive(state, Settings.get('reactivityMode'), true) | ||
}, | ||
} |
@@ -35,3 +35,4 @@ /* | ||
}, | ||
Settings.get('reactivityMode') | ||
Settings.get('reactivityMode'), | ||
true | ||
) | ||
@@ -38,0 +39,0 @@ |
@@ -55,3 +55,4 @@ /* | ||
}, | ||
Settings.get('reactivityMode') | ||
Settings.get('reactivityMode'), | ||
true | ||
) | ||
@@ -58,0 +59,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
573960
12369