@joist/observable 2.0.0-alpha.18 → 2.0.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -92,10 +92,10 @@ class TestElement extends HTMLElement {
|
|
|
92
92
|
|
|
93
93
|
// reads as a Date object and writes back a string
|
|
94
94
|
@observe
|
|
95
|
-
@attr({
|
|
96
|
-
read: (val
|
|
97
|
-
write: (val
|
|
95
|
+
@attr<Date>({
|
|
96
|
+
read: (val) => new Date(val),
|
|
97
|
+
write: (val) => val.toString()
|
|
98
98
|
})
|
|
99
|
-
count
|
|
99
|
+
count = new Date();
|
|
100
100
|
}
|
|
101
101
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joist/observable",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.20",
|
|
4
4
|
"main": "./target/build/lib.js",
|
|
5
5
|
"module": "./target/build/lib.js",
|
|
6
6
|
"exports": {
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"test": "tsc -p tsconfig.test.json && wtr --config ../../wtr.config.mjs --port 8002",
|
|
36
36
|
"build": "tsc -p tsconfig.build.json"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "9b62852b4fdfea6eebbf128d55537adbd368faf2"
|
|
39
39
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AttributeParser } from './attribute-parsers';
|
|
2
2
|
export declare function getObservableAttributes(c: typeof HTMLElement): Array<string>;
|
|
3
3
|
export declare function getAttributeParsers<T extends typeof HTMLElement>(c: T): Record<string, AttributeParser<unknown>>;
|
|
4
|
-
export declare function attr<T
|
|
4
|
+
export declare function attr<T>(p: Partial<AttributeParser<T>>): <E extends HTMLElement>(t: E, key: string) => void;
|
|
5
5
|
export declare function attr<T extends HTMLElement>(t: T, key: string): void;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { defaultParser, propNameToAttrName, } from './attribute-parsers';
|
|
2
2
|
export function getObservableAttributes(c) {
|
|
3
|
-
|
|
4
|
-
return attrs.map(propNameToAttrName);
|
|
3
|
+
return Reflect.get(c, 'observedAttributes') || [];
|
|
5
4
|
}
|
|
6
5
|
export function getAttributeParsers(c) {
|
|
7
6
|
const parsers = Reflect.get(c, 'attributeParsers') || {};
|
|
8
7
|
return parsers;
|
|
9
8
|
}
|
|
10
9
|
export function attr(targetOrParser, key) {
|
|
11
|
-
if (targetOrParser instanceof HTMLElement) {
|
|
10
|
+
if (targetOrParser instanceof HTMLElement && typeof key === 'string') {
|
|
12
11
|
const attrName = propNameToAttrName(key);
|
|
13
12
|
return defineAttribute(targetOrParser, attrName, key);
|
|
14
13
|
}
|
|
@@ -57,9 +57,9 @@ export function observable(Base) {
|
|
|
57
57
|
onPropertyChanged(changes) {
|
|
58
58
|
if (this instanceof HTMLElement) {
|
|
59
59
|
for (let change in changes) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
60
|
+
const attrName = propNameToAttrName(change);
|
|
61
|
+
if (attributes.includes(attrName)) {
|
|
62
|
+
const value = parsers[attrName].write(changes[change].value);
|
|
63
63
|
if (value !== this.getAttribute(attrName)) {
|
|
64
64
|
this.setAttribute(attrName, value);
|
|
65
65
|
}
|