@joist/observable 2.0.0 → 2.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joist/observable",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
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": "ed9e8f0cb4c6213ba255278a173c3dc7f45aee89"
38
+ "gitHead": "79cfc1519586b9bb83a3d1bd62e6db747f748bab"
39
39
  }
@@ -1,8 +0,0 @@
1
- import { Changes } from './observable';
2
- export declare class ObservableElement extends HTMLElement {
3
- __upgradedProps: Map<keyof this, unknown>;
4
- constructor();
5
- connectedCallback(): void;
6
- attributeChangedCallback(name: string, _: string, newVal: string): void;
7
- onPropertyChanged(changes: Changes): void;
8
- }
@@ -1,47 +0,0 @@
1
- import { getAttributeParsers, getObservableAttributes } from './attribute';
2
- import { propNameToAttrName } from './attribute-parsers';
3
- export class ObservableElement extends HTMLElement {
4
- constructor() {
5
- super();
6
- this.__upgradedProps = new Map();
7
- for (let prop in this) {
8
- if (this.hasOwnProperty(prop) && prop !== 'upgradedProps') {
9
- this.__upgradedProps.set(prop, this[prop]);
10
- }
11
- }
12
- }
13
- connectedCallback() {
14
- const attributes = getObservableAttributes(this.constructor);
15
- const parsers = getAttributeParsers(this.constructor);
16
- for (let i = 0; i < attributes.length; i++) {
17
- const key = attributes[i];
18
- const { write, mapTo } = parsers[key];
19
- if (this.getAttribute(key) === null) {
20
- const propVal = Reflect.get(this, mapTo);
21
- if (propVal !== undefined && propVal !== null && propVal !== '') {
22
- this.setAttribute(key, write(propVal));
23
- }
24
- }
25
- }
26
- }
27
- attributeChangedCallback(name, _, newVal) {
28
- const parsers = getAttributeParsers(this.constructor);
29
- const { read, mapTo } = parsers[name];
30
- Reflect.set(this, mapTo, read(newVal));
31
- }
32
- onPropertyChanged(changes) {
33
- const attributes = getObservableAttributes(this.constructor);
34
- const parsers = getAttributeParsers(this.constructor);
35
- if (this instanceof ObservableElement) {
36
- for (let change in changes) {
37
- const attrName = propNameToAttrName(change);
38
- if (attributes.includes(attrName)) {
39
- const value = parsers[attrName].write(changes[change].value);
40
- if (value !== this.getAttribute(attrName)) {
41
- this.setAttribute(attrName, value);
42
- }
43
- }
44
- }
45
- }
46
- }
47
- }