fix set
This commit is contained in:
26
sigpro2.js
26
sigpro2.js
@@ -1,3 +1,4 @@
|
|||||||
|
// sigpro 1.2.0
|
||||||
const isFunc = f => typeof f === "function"
|
const isFunc = f => typeof f === "function"
|
||||||
const isObj = o => o && typeof o === "object"
|
const isObj = o => o && typeof o === "object"
|
||||||
const isArr = Array.isArray
|
const isArr = Array.isArray
|
||||||
@@ -31,6 +32,10 @@ const dispose = eff => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onMount = fn => {
|
||||||
|
if (activeOwner) (activeOwner._mounts ||= []).push(fn)
|
||||||
|
}
|
||||||
|
|
||||||
const onUnmount = fn => {
|
const onUnmount = fn => {
|
||||||
if (activeOwner) (activeOwner._cleanups ||= new Set()).add(fn)
|
if (activeOwner) (activeOwner._cleanups ||= new Set()).add(fn)
|
||||||
}
|
}
|
||||||
@@ -100,10 +105,6 @@ const untrack = fn => {
|
|||||||
try { return fn() } finally { activeEffect = p }
|
try { return fn() } finally { activeEffect = p }
|
||||||
}
|
}
|
||||||
|
|
||||||
const onMount = fn => {
|
|
||||||
if (activeOwner) (activeOwner._mounts ||= []).push(fn)
|
|
||||||
}
|
|
||||||
|
|
||||||
const $ = (val, key = null) => {
|
const $ = (val, key = null) => {
|
||||||
const subs = new Set()
|
const subs = new Set()
|
||||||
if (isFunc(val)) {
|
if (isFunc(val)) {
|
||||||
@@ -463,18 +464,11 @@ const Mount = (comp, target) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const set = (signal, path, value) => {
|
const set = (signal, path, value) => {
|
||||||
if (value === undefined) {
|
if (value === undefined) return signal(isFunc(path) ? path(signal()) : path)
|
||||||
signal(isFunc(path) ? path(signal()) : path)
|
const keys = path.split('.'), root = { ...signal() }
|
||||||
return
|
let acc = root, k
|
||||||
}
|
for (k of keys.slice(0, -1)) acc = acc[k] = { ...(acc[k] || {}) }
|
||||||
const keys = path.split('.')
|
acc[keys.at(-1)] = value
|
||||||
const last = keys.pop()
|
|
||||||
const current = signal()
|
|
||||||
const root = { ...current }
|
|
||||||
let acc = root
|
|
||||||
for (const k of keys) acc = acc[k] = { ...acc[k] }
|
|
||||||
acc[last] = value
|
|
||||||
|
|
||||||
signal(root)
|
signal(root)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user