@joist/observable 2.0.0-next.6 → 2.0.0-next.7

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-next.6",
3
+ "version": "2.0.0-next.7",
4
4
  "main": "./target/build/lib.js",
5
5
  "module": "./target/build/lib.js",
6
6
  "exports": {
@@ -34,5 +34,5 @@
34
34
  "test": "tsc -p tsconfig.test.json && wtr --config ../../wtr.config.mjs --port 8002",
35
35
  "build": "tsc -p tsconfig.build.json"
36
36
  },
37
- "gitHead": "c99017a6f57235948d3753db16743ee23118c91a"
37
+ "gitHead": "48190a6eb436c5dcfd6f5b0b358e78d7722c577e"
38
38
  }
@@ -15,8 +15,8 @@ export interface ObservableBase {
15
15
  initializedChanges: Set<string | symbol>;
16
16
  definePropChange(key: string | symbol, propChange: Change): Promise<void>;
17
17
  }
18
- export declare function observe(): (target: any, key: string) => void;
19
- export declare function observable(): <T extends new (...args: any[]) => any>(CustomElement: T) => {
18
+ export declare function observe(target: any, key: string): void;
19
+ export declare function observable<T extends new (...args: any[]) => any>(CustomElement: T): {
20
20
  new (...args: any[]): {
21
21
  [x: string]: any;
22
22
  propChanges: Changes;
@@ -12,52 +12,48 @@ export function readPropertyDefs(c) {
12
12
  return c.properties || c.prototype.properties || {};
13
13
  }
14
14
  const PROPERTY_KEY = 'properties';
15
- export function observe() {
16
- return function (target, key) {
17
- target[PROPERTY_KEY] = target[PROPERTY_KEY] || {};
18
- target[PROPERTY_KEY][key] = {};
19
- };
15
+ export function observe(target, key) {
16
+ target[PROPERTY_KEY] = target[PROPERTY_KEY] || {};
17
+ target[PROPERTY_KEY][key] = {};
20
18
  }
21
- export function observable() {
22
- return (CustomElement) => {
23
- const defs = readPropertyDefs(CustomElement);
24
- const props = createPropertyDescripors(defs);
25
- return class ObservableElement extends CustomElement {
26
- propChanges = {};
27
- propChange = null;
28
- initializedChanges = new Set();
29
- constructor(...args) {
30
- super(...args);
31
- for (let def in defs) {
32
- Reflect.set(this, createPrivateKey(def), Reflect.get(this, def));
33
- }
34
- Object.defineProperties(this, props);
19
+ export function observable(CustomElement) {
20
+ const defs = readPropertyDefs(CustomElement);
21
+ const props = createPropertyDescripors(defs);
22
+ return class ObservableElement extends CustomElement {
23
+ propChanges = {};
24
+ propChange = null;
25
+ initializedChanges = new Set();
26
+ constructor(...args) {
27
+ super(...args);
28
+ for (let def in defs) {
29
+ Reflect.set(this, createPrivateKey(def), Reflect.get(this, def));
35
30
  }
36
- definePropChange(key, propChange) {
37
- if (!this.propChanges[key]) {
38
- this.propChanges[key] = propChange;
39
- }
40
- this.propChanges[key].value = propChange.value;
41
- if (!this.propChange) {
42
- // If there is no previous change defined set it up
43
- this.propChange = Promise.resolve().then(() => {
44
- // run onPropChanges here. This makes sure we capture all changes
45
- // keep track of whether or not this is the first time a given property has changes
46
- for (let change in this.propChanges) {
47
- this.propChanges[change].firstChange = !this.initializedChanges.has(change);
48
- this.initializedChanges.add(change);
49
- }
50
- if (this.onChange) {
51
- this.onChange(this.propChanges);
52
- }
53
- // reset for next time
54
- this.propChanges = {};
55
- this.propChange = null;
56
- });
57
- }
58
- return this.propChange;
31
+ Object.defineProperties(this, props);
32
+ }
33
+ definePropChange(key, propChange) {
34
+ if (!this.propChanges[key]) {
35
+ this.propChanges[key] = propChange;
59
36
  }
60
- };
37
+ this.propChanges[key].value = propChange.value;
38
+ if (!this.propChange) {
39
+ // If there is no previous change defined set it up
40
+ this.propChange = Promise.resolve().then(() => {
41
+ // run onPropChanges here. This makes sure we capture all changes
42
+ // keep track of whether or not this is the first time a given property has changes
43
+ for (let change in this.propChanges) {
44
+ this.propChanges[change].firstChange = !this.initializedChanges.has(change);
45
+ this.initializedChanges.add(change);
46
+ }
47
+ if (this.onChange) {
48
+ this.onChange(this.propChanges);
49
+ }
50
+ // reset for next time
51
+ this.propChanges = {};
52
+ this.propChange = null;
53
+ });
54
+ }
55
+ return this.propChange;
56
+ }
61
57
  };
62
58
  }
63
59
  function createPrivateKey(key) {
@@ -1 +1 @@
1
- {"version":3,"file":"observable.js","sourceRoot":"","sources":["../../../lib/observable.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,MAAM;IACE;IAAiB;IAAqC;IAAzE,YAAmB,KAAQ,EAAS,aAA4B,EAAS,WAAoB;QAA1E,UAAK,GAAL,KAAK,CAAG;QAAS,kBAAa,GAAb,aAAa,CAAe;QAAS,gBAAW,GAAX,WAAW,CAAS;IAAG,CAAC;CAClG;AAQD,MAAM,UAAU,gBAAgB,CAAC,CAAM;IACrC,OAAO,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,SAAS,CAAC,UAAU,IAAI,EAAE,CAAC;AACtD,CAAC;AASD,MAAM,YAAY,GAAG,YAAY,CAAC;AAElC,MAAM,UAAU,OAAO;IACrB,OAAO,UAAU,MAAW,EAAE,GAAW;QACvC,MAAM,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;QAClD,MAAM,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;IACjC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO,CAAwC,aAAgB,EAAE,EAAE;QACjE,MAAM,IAAI,GAAG,gBAAgB,CAAC,aAAa,CAAC,CAAC;QAC7C,MAAM,KAAK,GAAG,wBAAwB,CAAC,IAAI,CAAC,CAAC;QAE7C,OAAO,MAAM,iBAAkB,SAAQ,aAAa;YAClD,WAAW,GAAY,EAAE,CAAC;YAC1B,UAAU,GAAyB,IAAI,CAAC;YACxC,kBAAkB,GAAG,IAAI,GAAG,EAAmB,CAAC;YAEhD,YAAY,GAAG,IAAW;gBACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;gBAEf,KAAK,IAAI,GAAG,IAAI,IAAI,EAAE;oBACpB,OAAO,CAAC,GAAG,CAA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