1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2025-03-31 11:35:52 +02:00

Signal ← SignalReadonly

This commit is contained in:
Jan Andrle 2025-03-19 10:02:33 +01:00
parent a459c0d786
commit 74ed180919
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
6 changed files with 24 additions and 35 deletions

View File

@ -696,13 +696,10 @@ var queueSignalWrite = /* @__PURE__ */ (() => {
})();
// src/signals-lib/signals-lib.js
var Signal = oCreate(null, {
var SignalReadOnly = oCreate(null, {
get: { value() {
return read(this);
} },
set: { value(...v) {
return write(this, ...v);
} },
toJSON: { value() {
return read(this);
} },
@ -710,9 +707,9 @@ var Signal = oCreate(null, {
return this[mark] && this[mark].value;
} }
});
var SignalReadOnly = oCreate(Signal, {
set: { value() {
return;
var Signal = oCreate(SignalReadOnly, {
set: { value(...v) {
return write(this, ...v);
} }
});
function isSignal(candidate) {
@ -906,7 +903,7 @@ var cleanUpRegistry = new FinalizationRegistry(function(s) {
});
function create(is_readonly, value, actions) {
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]);
return SI;
}
@ -918,7 +915,7 @@ var protoSigal = oAssign(oCreate(), {
this.skip = true;
}
});
function toSignal(s, value, actions, readonly = false) {
function toSignal(s, value, actions) {
const onclear = [];
if (typeOf(actions) !== "[object Object]")
actions = {};
@ -934,8 +931,7 @@ function toSignal(s, value, actions, readonly = false) {
actions,
onclear,
host,
listeners: /* @__PURE__ */ new Set(),
readonly
listeners: /* @__PURE__ */ new Set()
}),
enumerable: false,
writable: false,

File diff suppressed because one or more lines are too long

View File

@ -741,13 +741,10 @@ var DDE = (() => {
})();
// src/signals-lib/signals-lib.js
var Signal = oCreate(null, {
var SignalReadOnly = oCreate(null, {
get: { value() {
return read(this);
} },
set: { value(...v) {
return write(this, ...v);
} },
toJSON: { value() {
return read(this);
} },
@ -755,9 +752,9 @@ var DDE = (() => {
return this[mark] && this[mark].value;
} }
});
var SignalReadOnly = oCreate(Signal, {
set: { value() {
return;
var Signal = oCreate(SignalReadOnly, {
set: { value(...v) {
return write(this, ...v);
} }
});
function isSignal(candidate) {
@ -951,7 +948,7 @@ var DDE = (() => {
});
function create(is_readonly, value, actions) {
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]);
return SI;
}
@ -963,7 +960,7 @@ var DDE = (() => {
this.skip = true;
}
});
function toSignal(s, value, actions, readonly = false) {
function toSignal(s, value, actions) {
const onclear = [];
if (typeOf(actions) !== "[object Object]")
actions = {};
@ -979,8 +976,7 @@ var DDE = (() => {
actions,
onclear,
host,
listeners: /* @__PURE__ */ new Set(),
readonly
listeners: /* @__PURE__ */ new Set()
}),
enumerable: false,
writable: false,

File diff suppressed because one or more lines are too long

View File

@ -77,11 +77,11 @@ export function page({ pkg, info }){
signal objects. It contains the following information:
`),
el("ul").append(
// TODO: value?
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`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`readonly: Boolean flag indicating if the signal is read-only`)
),
el("p").append(T`
to determine the current value of the signal, call ${el("code", "signal.valueOf()")}. Dont hesitate to

View File

@ -2,14 +2,13 @@ import { queueSignalWrite, mark } from "./helpers.js";
export { mark };
import { hasOwn, oCreate, oAssign, requestIdle } from "../helpers.js";
const Signal = oCreate(null, {
const SignalReadOnly= oCreate(null, {
get: { value(){ return read(this); } },
set: { value(...v){ return write(this, ...v); } },
toJSON: { value(){ return read(this); } },
valueOf: { value(){ return this[mark] && this[mark].value; } }
});
const SignalReadOnly= oCreate(Signal, {
set: { value(){ return; } },
const Signal = oCreate(SignalReadOnly, {
set: { value(...v){ return write(this, ...v); } },
});
/**
* Checks if a value is a signal
@ -344,7 +343,7 @@ const cleanUpRegistry = new FinalizationRegistry(function(s){
*/
function create(is_readonly, value, actions){
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]);
return SI;
}
@ -367,11 +366,10 @@ const protoSigal= oAssign(oCreate(), {
* @param {Object} s - Object to transform
* @param {any} value - Initial value
* @param {Object} actions - Custom actions
* @param {boolean} [readonly=false] - Whether the signal is readonly
* @returns {Object} Signal object with get() and set() methods
* @private
*/
function toSignal(s, value, actions, readonly= false){
function toSignal(s, value, actions){
const onclear= [];
if(typeOf(actions)!=="[object Object]")
actions= {};
@ -385,7 +383,6 @@ function toSignal(s, value, actions, readonly= false){
value: oAssign(oCreate(protoSigal), {
value, actions, onclear, host,
listeners: new Set(),
readonly
}),
enumerable: false,
writable: false,