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 isObj = o => o && typeof o === "object"
|
||||
const isArr = Array.isArray
|
||||
@@ -31,6 +32,10 @@ const dispose = eff => {
|
||||
}
|
||||
}
|
||||
|
||||
const onMount = fn => {
|
||||
if (activeOwner) (activeOwner._mounts ||= []).push(fn)
|
||||
}
|
||||
|
||||
const onUnmount = fn => {
|
||||
if (activeOwner) (activeOwner._cleanups ||= new Set()).add(fn)
|
||||
}
|
||||
@@ -100,10 +105,6 @@ const untrack = fn => {
|
||||
try { return fn() } finally { activeEffect = p }
|
||||
}
|
||||
|
||||
const onMount = fn => {
|
||||
if (activeOwner) (activeOwner._mounts ||= []).push(fn)
|
||||
}
|
||||
|
||||
const $ = (val, key = null) => {
|
||||
const subs = new Set()
|
||||
if (isFunc(val)) {
|
||||
@@ -463,18 +464,11 @@ const Mount = (comp, target) => {
|
||||
}
|
||||
|
||||
const set = (signal, path, value) => {
|
||||
if (value === undefined) {
|
||||
signal(isFunc(path) ? path(signal()) : path)
|
||||
return
|
||||
}
|
||||
const keys = path.split('.')
|
||||
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
|
||||
|
||||
if (value === undefined) return signal(isFunc(path) ? path(signal()) : path)
|
||||
const keys = path.split('.'), root = { ...signal() }
|
||||
let acc = root, k
|
||||
for (k of keys.slice(0, -1)) acc = acc[k] = { ...(acc[k] || {}) }
|
||||
acc[keys.at(-1)] = value
|
||||
signal(root)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user