mirror of
https://github.com/jaandrle/deka-dom-el
synced 2025-04-02 04:05:52 +02:00
⚡ Signal ← SignalReadonly
This commit is contained in:
parent
a459c0d786
commit
74ed180919
18
dist/esm-with-signals.js
vendored
18
dist/esm-with-signals.js
vendored
@ -696,13 +696,10 @@ var queueSignalWrite = /* @__PURE__ */ (() => {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
// src/signals-lib/signals-lib.js
|
// src/signals-lib/signals-lib.js
|
||||||
var Signal = oCreate(null, {
|
var SignalReadOnly = oCreate(null, {
|
||||||
get: { value() {
|
get: { value() {
|
||||||
return read(this);
|
return read(this);
|
||||||
} },
|
} },
|
||||||
set: { value(...v) {
|
|
||||||
return write(this, ...v);
|
|
||||||
} },
|
|
||||||
toJSON: { value() {
|
toJSON: { value() {
|
||||||
return read(this);
|
return read(this);
|
||||||
} },
|
} },
|
||||||
@ -710,9 +707,9 @@ var Signal = oCreate(null, {
|
|||||||
return this[mark] && this[mark].value;
|
return this[mark] && this[mark].value;
|
||||||
} }
|
} }
|
||||||
});
|
});
|
||||||
var SignalReadOnly = oCreate(Signal, {
|
var Signal = oCreate(SignalReadOnly, {
|
||||||
set: { value() {
|
set: { value(...v) {
|
||||||
return;
|
return write(this, ...v);
|
||||||
} }
|
} }
|
||||||
});
|
});
|
||||||
function isSignal(candidate) {
|
function isSignal(candidate) {
|
||||||
@ -906,7 +903,7 @@ var cleanUpRegistry = new FinalizationRegistry(function(s) {
|
|||||||
});
|
});
|
||||||
function create(is_readonly, value, actions) {
|
function create(is_readonly, value, actions) {
|
||||||
const varS = oCreate(is_readonly ? SignalReadOnly : Signal);
|
const varS = oCreate(is_readonly ? SignalReadOnly : Signal);
|
||||||
const SI = toSignal(varS, value, actions, is_readonly);
|
const SI = toSignal(varS, value, actions);
|
||||||
cleanUpRegistry.register(SI, SI[mark]);
|
cleanUpRegistry.register(SI, SI[mark]);
|
||||||
return SI;
|
return SI;
|
||||||
}
|
}
|
||||||
@ -918,7 +915,7 @@ var protoSigal = oAssign(oCreate(), {
|
|||||||
this.skip = true;
|
this.skip = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
function toSignal(s, value, actions, readonly = false) {
|
function toSignal(s, value, actions) {
|
||||||
const onclear = [];
|
const onclear = [];
|
||||||
if (typeOf(actions) !== "[object Object]")
|
if (typeOf(actions) !== "[object Object]")
|
||||||
actions = {};
|
actions = {};
|
||||||
@ -934,8 +931,7 @@ function toSignal(s, value, actions, readonly = false) {
|
|||||||
actions,
|
actions,
|
||||||
onclear,
|
onclear,
|
||||||
host,
|
host,
|
||||||
listeners: /* @__PURE__ */ new Set(),
|
listeners: /* @__PURE__ */ new Set()
|
||||||
readonly
|
|
||||||
}),
|
}),
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
writable: false,
|
writable: false,
|
||||||
|
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
18
dist/iife-with-signals.js
vendored
18
dist/iife-with-signals.js
vendored
@ -741,13 +741,10 @@ var DDE = (() => {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
// src/signals-lib/signals-lib.js
|
// src/signals-lib/signals-lib.js
|
||||||
var Signal = oCreate(null, {
|
var SignalReadOnly = oCreate(null, {
|
||||||
get: { value() {
|
get: { value() {
|
||||||
return read(this);
|
return read(this);
|
||||||
} },
|
} },
|
||||||
set: { value(...v) {
|
|
||||||
return write(this, ...v);
|
|
||||||
} },
|
|
||||||
toJSON: { value() {
|
toJSON: { value() {
|
||||||
return read(this);
|
return read(this);
|
||||||
} },
|
} },
|
||||||
@ -755,9 +752,9 @@ var DDE = (() => {
|
|||||||
return this[mark] && this[mark].value;
|
return this[mark] && this[mark].value;
|
||||||
} }
|
} }
|
||||||
});
|
});
|
||||||
var SignalReadOnly = oCreate(Signal, {
|
var Signal = oCreate(SignalReadOnly, {
|
||||||
set: { value() {
|
set: { value(...v) {
|
||||||
return;
|
return write(this, ...v);
|
||||||
} }
|
} }
|
||||||
});
|
});
|
||||||
function isSignal(candidate) {
|
function isSignal(candidate) {
|
||||||
@ -951,7 +948,7 @@ var DDE = (() => {
|
|||||||
});
|
});
|
||||||
function create(is_readonly, value, actions) {
|
function create(is_readonly, value, actions) {
|
||||||
const varS = oCreate(is_readonly ? SignalReadOnly : Signal);
|
const varS = oCreate(is_readonly ? SignalReadOnly : Signal);
|
||||||
const SI = toSignal(varS, value, actions, is_readonly);
|
const SI = toSignal(varS, value, actions);
|
||||||
cleanUpRegistry.register(SI, SI[mark]);
|
cleanUpRegistry.register(SI, SI[mark]);
|
||||||
return SI;
|
return SI;
|
||||||
}
|
}
|
||||||
@ -963,7 +960,7 @@ var DDE = (() => {
|
|||||||
this.skip = true;
|
this.skip = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
function toSignal(s, value, actions, readonly = false) {
|
function toSignal(s, value, actions) {
|
||||||
const onclear = [];
|
const onclear = [];
|
||||||
if (typeOf(actions) !== "[object Object]")
|
if (typeOf(actions) !== "[object Object]")
|
||||||
actions = {};
|
actions = {};
|
||||||
@ -979,8 +976,7 @@ var DDE = (() => {
|
|||||||
actions,
|
actions,
|
||||||
onclear,
|
onclear,
|
||||||
host,
|
host,
|
||||||
listeners: /* @__PURE__ */ new Set(),
|
listeners: /* @__PURE__ */ new Set()
|
||||||
readonly
|
|
||||||
}),
|
}),
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
writable: false,
|
writable: false,
|
||||||
|
4
dist/iife-with-signals.min.js
vendored
4
dist/iife-with-signals.min.js
vendored
File diff suppressed because one or more lines are too long
@ -77,11 +77,11 @@ export function page({ pkg, info }){
|
|||||||
signal objects. It contains the following information:
|
signal objects. It contains the following information:
|
||||||
`),
|
`),
|
||||||
el("ul").append(
|
el("ul").append(
|
||||||
|
// TODO: value?
|
||||||
el("li", t`listeners: A Set of functions called when the signal value changes`),
|
el("li", t`listeners: A Set of functions called when the signal value changes`),
|
||||||
el("li", t`actions: Custom actions that can be performed on the signal`),
|
el("li", t`actions: Custom actions that can be performed on the signal`),
|
||||||
el("li", t`onclear: Functions to run when the signal is cleared`),
|
el("li", t`onclear: Functions to run when the signal is cleared`),
|
||||||
el("li", t`host: Reference to the host element/scope in which the signal was created`),
|
el("li", t`host: Reference to the host element/scope in which the signal was created`),
|
||||||
el("li", t`readonly: Boolean flag indicating if the signal is read-only`)
|
|
||||||
),
|
),
|
||||||
el("p").append(T`
|
el("p").append(T`
|
||||||
…to determine the current value of the signal, call ${el("code", "signal.valueOf()")}. Don’t hesitate to
|
…to determine the current value of the signal, call ${el("code", "signal.valueOf()")}. Don’t hesitate to
|
||||||
|
@ -2,14 +2,13 @@ import { queueSignalWrite, mark } from "./helpers.js";
|
|||||||
export { mark };
|
export { mark };
|
||||||
import { hasOwn, oCreate, oAssign, requestIdle } from "../helpers.js";
|
import { hasOwn, oCreate, oAssign, requestIdle } from "../helpers.js";
|
||||||
|
|
||||||
const Signal = oCreate(null, {
|
const SignalReadOnly= oCreate(null, {
|
||||||
get: { value(){ return read(this); } },
|
get: { value(){ return read(this); } },
|
||||||
set: { value(...v){ return write(this, ...v); } },
|
|
||||||
toJSON: { value(){ return read(this); } },
|
toJSON: { value(){ return read(this); } },
|
||||||
valueOf: { value(){ return this[mark] && this[mark].value; } }
|
valueOf: { value(){ return this[mark] && this[mark].value; } }
|
||||||
});
|
});
|
||||||
const SignalReadOnly= oCreate(Signal, {
|
const Signal = oCreate(SignalReadOnly, {
|
||||||
set: { value(){ return; } },
|
set: { value(...v){ return write(this, ...v); } },
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
* Checks if a value is a signal
|
* Checks if a value is a signal
|
||||||
@ -344,7 +343,7 @@ const cleanUpRegistry = new FinalizationRegistry(function(s){
|
|||||||
*/
|
*/
|
||||||
function create(is_readonly, value, actions){
|
function create(is_readonly, value, actions){
|
||||||
const varS = oCreate(is_readonly ? SignalReadOnly : Signal);
|
const varS = oCreate(is_readonly ? SignalReadOnly : Signal);
|
||||||
const SI= toSignal(varS, value, actions, is_readonly);
|
const SI= toSignal(varS, value, actions);
|
||||||
cleanUpRegistry.register(SI, SI[mark]);
|
cleanUpRegistry.register(SI, SI[mark]);
|
||||||
return SI;
|
return SI;
|
||||||
}
|
}
|
||||||
@ -367,11 +366,10 @@ const protoSigal= oAssign(oCreate(), {
|
|||||||
* @param {Object} s - Object to transform
|
* @param {Object} s - Object to transform
|
||||||
* @param {any} value - Initial value
|
* @param {any} value - Initial value
|
||||||
* @param {Object} actions - Custom actions
|
* @param {Object} actions - Custom actions
|
||||||
* @param {boolean} [readonly=false] - Whether the signal is readonly
|
|
||||||
* @returns {Object} Signal object with get() and set() methods
|
* @returns {Object} Signal object with get() and set() methods
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function toSignal(s, value, actions, readonly= false){
|
function toSignal(s, value, actions){
|
||||||
const onclear= [];
|
const onclear= [];
|
||||||
if(typeOf(actions)!=="[object Object]")
|
if(typeOf(actions)!=="[object Object]")
|
||||||
actions= {};
|
actions= {};
|
||||||
@ -385,7 +383,6 @@ function toSignal(s, value, actions, readonly= false){
|
|||||||
value: oAssign(oCreate(protoSigal), {
|
value: oAssign(oCreate(protoSigal), {
|
||||||
value, actions, onclear, host,
|
value, actions, onclear, host,
|
||||||
listeners: new Set(),
|
listeners: new Set(),
|
||||||
readonly
|
|
||||||
}),
|
}),
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
writable: false,
|
writable: false,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user