mirror of
https://github.com/jaandrle/deka-dom-el
synced 2025-04-06 13:37:07 +02:00
🐛 fixes #38
This commit is contained in:
parent
44c28f1bd2
commit
df8095e1cb
dist
docs/components/examples/case-studies
src/signals-lib
20
dist/esm-with-signals.js
vendored
20
dist/esm-with-signals.js
vendored
@ -689,19 +689,19 @@ memo.scope = function memoScope(fun, { signal: signal2, onlyLast } = {}) {
|
|||||||
// src/signals-lib/helpers.js
|
// src/signals-lib/helpers.js
|
||||||
var mark = "__dde_signal";
|
var mark = "__dde_signal";
|
||||||
var queueSignalWrite = /* @__PURE__ */ (() => {
|
var queueSignalWrite = /* @__PURE__ */ (() => {
|
||||||
let pendingSignals = /* @__PURE__ */ new Set();
|
let pendingSignals = /* @__PURE__ */ new Map();
|
||||||
let scheduled = false;
|
let scheduled = false;
|
||||||
function flushSignals() {
|
function flushSignals() {
|
||||||
scheduled = false;
|
scheduled = false;
|
||||||
const todo = pendingSignals;
|
const todo = pendingSignals;
|
||||||
pendingSignals = /* @__PURE__ */ new Set();
|
pendingSignals = /* @__PURE__ */ new Map();
|
||||||
for (const signal2 of todo) {
|
for (const [signal2, force] of todo) {
|
||||||
const M = signal2[mark];
|
const M = signal2[mark];
|
||||||
if (M) M.listeners.forEach((l) => l(M.value));
|
if (M) M.listeners.forEach((l) => l(M.value, force));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return function(s) {
|
return function(s, force = false) {
|
||||||
pendingSignals.add(s);
|
pendingSignals.set(s, pendingSignals.get(s) || force);
|
||||||
if (scheduled) return;
|
if (scheduled) return;
|
||||||
scheduled = true;
|
scheduled = true;
|
||||||
queueMicrotask(flushSignals);
|
queueMicrotask(flushSignals);
|
||||||
@ -738,11 +738,11 @@ function signal(value, actions) {
|
|||||||
return create(false, value, actions);
|
return create(false, value, actions);
|
||||||
if (isSignal(value)) return value;
|
if (isSignal(value)) return value;
|
||||||
const out = create(true);
|
const out = create(true);
|
||||||
function contextReWatch() {
|
function contextReWatch(_, force) {
|
||||||
const [origin, ...deps_old] = deps.get(contextReWatch);
|
const [origin, ...deps_old] = deps.get(contextReWatch);
|
||||||
deps.set(contextReWatch, /* @__PURE__ */ new Set([origin]));
|
deps.set(contextReWatch, /* @__PURE__ */ new Set([origin]));
|
||||||
stack_watch.push(contextReWatch);
|
stack_watch.push(contextReWatch);
|
||||||
write(out, value());
|
write(out, value(), force);
|
||||||
stack_watch.pop();
|
stack_watch.pop();
|
||||||
if (!deps_old.length) return;
|
if (!deps_old.length) return;
|
||||||
const deps_curr = deps.get(contextReWatch);
|
const deps_curr = deps.get(contextReWatch);
|
||||||
@ -764,7 +764,7 @@ signal.action = function(s, name, ...a) {
|
|||||||
throw new Error(`Action "${name}" not defined. See ${mark}.actions.`);
|
throw new Error(`Action "${name}" not defined. See ${mark}.actions.`);
|
||||||
actions[name].apply(M, a);
|
actions[name].apply(M, a);
|
||||||
if (M.skip) return delete M.skip;
|
if (M.skip) return delete M.skip;
|
||||||
queueSignalWrite(s);
|
queueSignalWrite(s, true);
|
||||||
};
|
};
|
||||||
signal.on = function on2(s, listener, options = {}) {
|
signal.on = function on2(s, listener, options = {}) {
|
||||||
const { signal: as } = options;
|
const { signal: as } = options;
|
||||||
@ -973,7 +973,7 @@ function write(s, value, force) {
|
|||||||
const M = s[mark];
|
const M = s[mark];
|
||||||
if (!M || !force && M.value === value) return;
|
if (!M || !force && M.value === value) return;
|
||||||
M.value = value;
|
M.value = value;
|
||||||
queueSignalWrite(s);
|
queueSignalWrite(s, force);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
function addSignalListener(s, listener) {
|
function addSignalListener(s, listener) {
|
||||||
|
4
dist/esm-with-signals.min.js
vendored
4
dist/esm-with-signals.min.js
vendored
File diff suppressed because one or more lines are too long
20
dist/iife-with-signals.js
vendored
20
dist/iife-with-signals.js
vendored
@ -734,19 +734,19 @@ var DDE = (() => {
|
|||||||
// src/signals-lib/helpers.js
|
// src/signals-lib/helpers.js
|
||||||
var mark = "__dde_signal";
|
var mark = "__dde_signal";
|
||||||
var queueSignalWrite = /* @__PURE__ */ (() => {
|
var queueSignalWrite = /* @__PURE__ */ (() => {
|
||||||
let pendingSignals = /* @__PURE__ */ new Set();
|
let pendingSignals = /* @__PURE__ */ new Map();
|
||||||
let scheduled = false;
|
let scheduled = false;
|
||||||
function flushSignals() {
|
function flushSignals() {
|
||||||
scheduled = false;
|
scheduled = false;
|
||||||
const todo = pendingSignals;
|
const todo = pendingSignals;
|
||||||
pendingSignals = /* @__PURE__ */ new Set();
|
pendingSignals = /* @__PURE__ */ new Map();
|
||||||
for (const signal2 of todo) {
|
for (const [signal2, force] of todo) {
|
||||||
const M = signal2[mark];
|
const M = signal2[mark];
|
||||||
if (M) M.listeners.forEach((l) => l(M.value));
|
if (M) M.listeners.forEach((l) => l(M.value, force));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return function(s) {
|
return function(s, force = false) {
|
||||||
pendingSignals.add(s);
|
pendingSignals.set(s, pendingSignals.get(s) || force);
|
||||||
if (scheduled) return;
|
if (scheduled) return;
|
||||||
scheduled = true;
|
scheduled = true;
|
||||||
queueMicrotask(flushSignals);
|
queueMicrotask(flushSignals);
|
||||||
@ -783,11 +783,11 @@ var DDE = (() => {
|
|||||||
return create(false, value, actions);
|
return create(false, value, actions);
|
||||||
if (isSignal(value)) return value;
|
if (isSignal(value)) return value;
|
||||||
const out = create(true);
|
const out = create(true);
|
||||||
function contextReWatch() {
|
function contextReWatch(_, force) {
|
||||||
const [origin, ...deps_old] = deps.get(contextReWatch);
|
const [origin, ...deps_old] = deps.get(contextReWatch);
|
||||||
deps.set(contextReWatch, /* @__PURE__ */ new Set([origin]));
|
deps.set(contextReWatch, /* @__PURE__ */ new Set([origin]));
|
||||||
stack_watch.push(contextReWatch);
|
stack_watch.push(contextReWatch);
|
||||||
write(out, value());
|
write(out, value(), force);
|
||||||
stack_watch.pop();
|
stack_watch.pop();
|
||||||
if (!deps_old.length) return;
|
if (!deps_old.length) return;
|
||||||
const deps_curr = deps.get(contextReWatch);
|
const deps_curr = deps.get(contextReWatch);
|
||||||
@ -809,7 +809,7 @@ var DDE = (() => {
|
|||||||
throw new Error(`Action "${name}" not defined. See ${mark}.actions.`);
|
throw new Error(`Action "${name}" not defined. See ${mark}.actions.`);
|
||||||
actions[name].apply(M, a);
|
actions[name].apply(M, a);
|
||||||
if (M.skip) return delete M.skip;
|
if (M.skip) return delete M.skip;
|
||||||
queueSignalWrite(s);
|
queueSignalWrite(s, true);
|
||||||
};
|
};
|
||||||
signal.on = function on2(s, listener, options = {}) {
|
signal.on = function on2(s, listener, options = {}) {
|
||||||
const { signal: as } = options;
|
const { signal: as } = options;
|
||||||
@ -1018,7 +1018,7 @@ var DDE = (() => {
|
|||||||
const M = s[mark];
|
const M = s[mark];
|
||||||
if (!M || !force && M.value === value) return;
|
if (!M || !force && M.value === value) return;
|
||||||
M.value = value;
|
M.value = value;
|
||||||
queueSignalWrite(s);
|
queueSignalWrite(s, force);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
function addSignalListener(s, listener) {
|
function addSignalListener(s, listener) {
|
||||||
|
6
dist/iife-with-signals.min.js
vendored
6
dist/iife-with-signals.min.js
vendored
File diff suppressed because one or more lines are too long
@ -58,9 +58,6 @@ export function TaskManager() {
|
|||||||
update(id, task) {
|
update(id, task) {
|
||||||
const current= this.value.find(t => t.id === id);
|
const current= this.value.find(t => t.id === id);
|
||||||
if (current) Object.assign(current, task);
|
if (current) Object.assign(current, task);
|
||||||
// TODO: known bug for derived signals (the object is the same)
|
|
||||||
// so filteredTasks is not updated, hotfix ↙
|
|
||||||
this.value = structuredClone(this.value);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const newTaskTitle = S('');
|
const newTaskTitle = S('');
|
||||||
|
@ -9,7 +9,8 @@ export const mark= "__dde_signal";
|
|||||||
* @type {Function}
|
* @type {Function}
|
||||||
*/
|
*/
|
||||||
export const queueSignalWrite= (()=> {
|
export const queueSignalWrite= (()=> {
|
||||||
let pendingSignals= new Set();
|
/** @type {Map<ddeSignal, boolean>} */
|
||||||
|
let pendingSignals= new Map();
|
||||||
let scheduled= false;
|
let scheduled= false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,19 +20,20 @@ export const queueSignalWrite= (()=> {
|
|||||||
function flushSignals() {
|
function flushSignals() {
|
||||||
scheduled = false;
|
scheduled = false;
|
||||||
const todo= pendingSignals;
|
const todo= pendingSignals;
|
||||||
pendingSignals= new Set();
|
pendingSignals= new Map();
|
||||||
for(const signal of todo){
|
for(const [ signal, force ] of todo){
|
||||||
const M = signal[mark];
|
const M = signal[mark];
|
||||||
if(M) M.listeners.forEach(l => l(M.value));
|
if(M) M.listeners.forEach(l => l(M.value, force));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queues a signal for update
|
* Queues a signal for update
|
||||||
* @param {Object} s - Signal to queue
|
* @param {ddeSignal} s - Signal to queue
|
||||||
|
* @param {boolean} force - Forced update
|
||||||
*/
|
*/
|
||||||
return function(s){
|
return function(s, force= false){
|
||||||
pendingSignals.add(s);
|
pendingSignals.set(s, pendingSignals.get(s) || force);
|
||||||
if(scheduled) return;
|
if(scheduled) return;
|
||||||
scheduled = true;
|
scheduled = true;
|
||||||
queueMicrotask(flushSignals);
|
queueMicrotask(flushSignals);
|
||||||
|
@ -57,12 +57,12 @@ export function signal(value, actions){
|
|||||||
* Updates the derived signal when dependencies change
|
* Updates the derived signal when dependencies change
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function contextReWatch(){
|
function contextReWatch(_, force){
|
||||||
const [ origin, ...deps_old ]= deps.get(contextReWatch);
|
const [ origin, ...deps_old ]= deps.get(contextReWatch);
|
||||||
deps.set(contextReWatch, new Set([ origin ]));
|
deps.set(contextReWatch, new Set([ origin ]));
|
||||||
|
|
||||||
stack_watch.push(contextReWatch);
|
stack_watch.push(contextReWatch);
|
||||||
write(out, value());
|
write(out, value(), force);
|
||||||
stack_watch.pop();
|
stack_watch.pop();
|
||||||
|
|
||||||
if(!deps_old.length) return;
|
if(!deps_old.length) return;
|
||||||
@ -95,7 +95,7 @@ signal.action= function(s, name, ...a){
|
|||||||
throw new Error(`Action "${name}" not defined. See ${mark}.actions.`);
|
throw new Error(`Action "${name}" not defined. See ${mark}.actions.`);
|
||||||
actions[name].apply(M, a);
|
actions[name].apply(M, a);
|
||||||
if(M.skip) return (delete M.skip);
|
if(M.skip) return (delete M.skip);
|
||||||
queueSignalWrite(s);
|
queueSignalWrite(s, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -434,7 +434,7 @@ function write(s, value, force){
|
|||||||
if(!M || (!force && M.value===value)) return;
|
if(!M || (!force && M.value===value)) return;
|
||||||
|
|
||||||
M.value= value;
|
M.value= value;
|
||||||
queueSignalWrite(s);
|
queueSignalWrite(s, force);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user