Skip to content

Commit

Permalink
fix properties
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-migdal committed Feb 27, 2025
1 parent 3f7c711 commit d41be6c
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 40 deletions.
7 changes: 6 additions & 1 deletion V3/src/LISS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import LISSBase from "./LISSClasses/LISSBase";
type Cstr<T> = new(...args:any[]) => T
type LISSv3_Opts<T extends Cstr<ContentGenerator> > = {
content_generator: T,
shadow : "null"|"open"|"closed"
} & ConstructorParameters<T>[0];

// builder
Expand All @@ -20,12 +21,16 @@ function LISS<
// @ts-ignore
const generator: ContentGenerator = new content_generator(opts);

let shadow = opts.shadow;
if( shadow === undefined)
shadow = "open"

// @ts-ignore
return class LISSBase extends base {

// TODO: no content if... ???
// override attachShadow ???
static override readonly SHADOW_MODE = "open";
static override readonly SHADOW_MODE = shadow;
static override readonly CONTENT_GENERATOR = generator;

}
Expand Down
17 changes: 0 additions & 17 deletions V3/src/LISSClasses/GCompoTest.ts

This file was deleted.

4 changes: 3 additions & 1 deletion V3/src/LISSClasses/LISSFather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export default class LISSFather extends LISSUpdate {
this.LISSChildren = null;

for(let i = 0; i < records.length; ++i)
this.processRemovedNodes(records[i].removedNodes);
this.processRemovedNodes(records[i].removedNodes);

this.requestUpdate();
});
}

Expand Down
8 changes: 4 additions & 4 deletions V3/src/LISSClasses/LISSProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Properties<T extends Record<string, any>> = {

export default class LISSProperties<T extends Record<string, any>> extends LISSSignal<T> {

#manager: PropertiesManager;
protected readonly manager: PropertiesManager;

static PropertiesDescriptor: PropertiesDescriptor = {};

Expand Down Expand Up @@ -41,10 +41,10 @@ export default class LISSProperties<T extends Record<string, any>> extends LISSS

super(value, signal);

this.#manager = new PropertiesManager(this, this.klass.PropertiesDescriptor, {});
this.manager = new PropertiesManager(this, this.klass.PropertiesDescriptor, {});

this.properties = new this.klass.PropertiesKlass(this.#manager);
this.defaultProperties = new this.klass.DefaultPropertiesKlass(this.#manager);
this.properties = new this.klass.PropertiesKlass(this.manager);
this.defaultProperties = new this.klass.DefaultPropertiesKlass(this.manager);

// getInitialPropertyValue => NON => setProperty() system...
// listen properties changes => if attached => requestUpdate
Expand Down
2 changes: 2 additions & 0 deletions V3/src/LISSClasses/LISSUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export default class LISSUpdate extends LISSBase {
super();

observer.observe(this);

this.requestUpdate();
}

#requestID: null|number = null;
Expand Down
33 changes: 26 additions & 7 deletions V3/src/properties/PropertiesManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ export function attrname2propname<T extends string>(attr_name: T): PropertyName<
return result as any;
}

export type PropertyDescriptor<T = unknown> = PropertyFullDescription<T>
| ((raw: string) => T);
export type PropertiesDescriptor = Record<string, PropertyDescriptor<unknown>>;
export type PropertyDescriptor<T = any> = PropertyFullDescription<T>
| ((raw: string) => T)
| T;
export type PropertiesDescriptor = Record<string, PropertyDescriptor>;

export default class PropertiesManager {

Expand All @@ -36,13 +37,19 @@ export default class PropertiesManager {

if( typeof props === "function" && props.constructor.name === "Function")
props = { parser: props };
else if( props === null || typeof props !== "object" || ! ("parser" in props) )
props = { fixed: props };

this.#properties[name] = new Property(props as PropertyFullDescription<unknown>);

if( name === "content" )
continue;

// TODO: remove (use property struct)
const vpropname = attrname2propname(name);
const dpropname = attrname2propname('default-' + name);
const v = getPropertyInitialValue(target, vpropname as any, cstrVals[vpropname] );
const d = getPropertyInitialValue(target, dpropname as any, cstrVals[dpropname] );
const v = getPropertyInitialValue(target, vpropname as any, cstrVals[vpropname] ) ?? null;
const d = getPropertyInitialValue(target, dpropname as any, cstrVals[dpropname] ) ?? null;

if( v !== null)
this.#properties[name].JS_value = v;
Expand All @@ -55,6 +62,15 @@ export default class PropertiesManager {
for(let i = 0; i < attrs.length; ++i)
this.#onAttrChanged(attrs[i], target.getAttribute(attrs[i]) );

if( "content" in propertiesDesc ) {

this.#onAttrChanged("content", target.textContent );

new MutationObserver( () => {
this.#onAttrChanged("content", target.textContent);
}).observe(target.host, {characterData: true, subtree: true});
}

// @ts-ignore
target.attributeChangedCallback = ( name: string,
oldV: string|null,
Expand All @@ -71,9 +87,12 @@ export default class PropertiesManager {
this.#properties[name].signal.listen( callback );
}

getSignal(name: string) {
return this.#properties[name].signal;
}

getValue(name: string) {
console.warn(name, this.#properties);
this.#properties[name].signal.value;
return this.#properties[name].signal.value;
}
getDefault(name: string) {
throw new Error("not implemented");
Expand Down
13 changes: 5 additions & 8 deletions V3/src/properties/Property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type PropertyFullDescription<T> = {

export default class Property<T = unknown> {

#signal: ROSignal<T>;
readonly signal: ROSignal<T>;

#HTML_valueSignal : ParsedSignal<T>;
#HTML_defaultSignal: ParsedSignal<T>;
Expand All @@ -28,7 +28,7 @@ export default class Property<T = unknown> {
this.#HTML_defaultSignal = new ParsedSignal<T>(args.parser);

if( args.fixed !== undefined) {
this.#signal = new Signal(args.fixed); // should be RO.
this.signal = new Signal(args.fixed); // should be RO.
return;
}

Expand All @@ -43,15 +43,12 @@ export default class Property<T = unknown> {
if( args.default !== undefined )
sources.push( new Signal(args.default) );

this.#signal = new PrioritySignal<T>(...sources);
}


get signal() {
return this.#signal;
this.signal = new PrioritySignal<T>(...sources);
}

set JS_value(value: T|null) {
console.warn('set', value);
console.trace();
this.#JS_valueSignal.value = value;
}
set JS_default(value: T|null) {
Expand Down
11 changes: 11 additions & 0 deletions V3/src/properties/parser/RAWDATA_PARSER.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function RAWDATA_PARSER(value: string) {

/*
if( value.includes('%') )
return generateSignal<any>(value);
*/

value = value.trim();

return new Function(`return ${value};`)();
};
8 changes: 6 additions & 2 deletions V3/src/signals/ParsedSignal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ export default class ParsedSignal<T> extends ROSignal<T> {
get value() {

if( this.#parsed === false ) {

// trigger without ack ignored
if( this.#str === null)
this.#signal.value = null;
else
this.#parser(this.#str, this.#signal);
else {
const result = this.#parser(this.#str, this.#signal);
if( result !== undefined )
this.#signal.value = result;
}

this.#parsed = true;
}
Expand Down
2 changes: 2 additions & 0 deletions V3/src/signals/PrioritySignal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export default class PrioritySignal<T> extends ROSignal<T> {
break;
}

console.warn("Prioritu", i, val);

this.#current_priority = i;

return val;
Expand Down
4 changes: 4 additions & 0 deletions V3/src/signals/Signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export default class Signal<T> extends IndirectSignal<T> {
super.source = source; // may trigger if source change
}

override get source() {
return super.source;
}

override get value() {

if( this.source !== null)
Expand Down

0 comments on commit d41be6c

Please sign in to comment.