r-state-tree 0.6.2 → 0.6.3

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.
@@ -7,7 +7,7 @@ export declare class ObjectAdministration<T extends object> extends Administrati
7
7
  hasMap: AtomMap<PropertyKey>;
8
8
  valuesMap: SignalMap<PropertyKey>;
9
9
  computedMap: Map<PropertyKey, ComputedNode<T[keyof T]>>;
10
- types: Map<PropertyKey, PropertyType>;
10
+ types: Map<PropertyKey, PropertyType | null>;
11
11
  isWriting: boolean;
12
12
  static proxyTraps: ProxyHandler<object>;
13
13
  constructor(source?: T);
@@ -66,13 +66,13 @@ function isPropertyKey(val) {
66
66
  return typeof val === "string" || typeof val === "number" || typeof val === "symbol";
67
67
  }
68
68
  function getPropertyType(key, obj) {
69
- const ctor = obj.constructor;
70
- const hasMetadata = ctor != null && ctor[Symbol.metadata] !== void 0;
69
+ const plain = isPlainObject(obj);
71
70
  const descriptor = getPropertyDescriptor$1(obj, key);
72
71
  if (descriptor?.value && typeof descriptor.value === "function") {
73
72
  return "action";
74
73
  }
75
- if (!hasMetadata) {
74
+ const isAccessor = descriptor && (typeof descriptor.get === "function" || typeof descriptor.set === "function");
75
+ if (plain) {
76
76
  return "observable";
77
77
  }
78
78
  const metadata = obj.constructor[Symbol.metadata];
@@ -89,6 +89,9 @@ function getPropertyType(key, obj) {
89
89
  return "observable";
90
90
  }
91
91
  }
92
+ if (isAccessor) {
93
+ return null;
94
+ }
92
95
  return "observable";
93
96
  }
94
97
  function getPropertyDescriptor$1(obj, key) {
@@ -329,7 +332,7 @@ class ObjectAdministration extends Administration {
329
332
  }
330
333
  getType(key) {
331
334
  let type = this.types.get(key);
332
- if (type === void 0) {
335
+ if (type === void 0 && !this.types.has(key)) {
333
336
  type = getPropertyType(key, this.source);
334
337
  this.types.set(key, type);
335
338
  }
@@ -347,6 +350,9 @@ class ObjectAdministration extends Administration {
347
350
  if (type === "computed") {
348
351
  return resolveNode(this.getComputed(key));
349
352
  }
353
+ if (type === null) {
354
+ return void 0;
355
+ }
350
356
  return resolveNode(this.valuesMap.getOrCreate(key, this.source[key]));
351
357
  }
352
358
  read(key, receiver = this.proxy) {
@@ -358,15 +364,16 @@ class ObjectAdministration extends Administration {
358
364
  this.atom.reportObserved();
359
365
  return Reflect.get(this.source, key, receiver);
360
366
  }
361
- if (key in this.source) {
362
- this.valuesMap.reportObserved(key, this.source[key]);
367
+ if (type === null) {
368
+ return Reflect.get(this.source, key, receiver);
363
369
  }
364
370
  this.atom.reportObserved();
365
371
  if (this.atom.observing) {
366
372
  this.hasMap.reportObserved(key);
367
373
  }
374
+ const value = Reflect.get(this.source, key, receiver);
375
+ this.valuesMap.reportObserved(key, value);
368
376
  if (type === "observable") {
369
- const value = Reflect.get(this.source, key, receiver);
370
377
  const shouldWrap = this.explicitObservables.has(key) || isObservable(value);
371
378
  if (shouldWrap && value && typeof value === "object" && !Object.isFrozen(value)) {
372
379
  const desc = getPropertyDescriptor$1(this.source, key);
@@ -380,13 +387,14 @@ class ObjectAdministration extends Administration {
380
387
  }
381
388
  return value;
382
389
  }
383
- return getAction(
384
- Reflect.get(this.source, key, receiver)
385
- );
390
+ return getAction(value);
386
391
  }
387
392
  explicitObservables = /* @__PURE__ */ new Set();
388
393
  write(key, newValue) {
389
394
  const type = this.getType(key);
395
+ if (type === null) {
396
+ return Reflect.set(this.source, key, newValue, this.proxy);
397
+ }
390
398
  if (type === "computed") {
391
399
  return signalsCore.batch(() => this.set(key, newValue));
392
400
  }
@@ -65,13 +65,13 @@ function isPropertyKey(val) {
65
65
  return typeof val === "string" || typeof val === "number" || typeof val === "symbol";
66
66
  }
67
67
  function getPropertyType(key, obj) {
68
- const ctor = obj.constructor;
69
- const hasMetadata = ctor != null && ctor[Symbol.metadata] !== void 0;
68
+ const plain = isPlainObject(obj);
70
69
  const descriptor = getPropertyDescriptor$1(obj, key);
71
70
  if (descriptor?.value && typeof descriptor.value === "function") {
72
71
  return "action";
73
72
  }
74
- if (!hasMetadata) {
73
+ const isAccessor = descriptor && (typeof descriptor.get === "function" || typeof descriptor.set === "function");
74
+ if (plain) {
75
75
  return "observable";
76
76
  }
77
77
  const metadata = obj.constructor[Symbol.metadata];
@@ -88,6 +88,9 @@ function getPropertyType(key, obj) {
88
88
  return "observable";
89
89
  }
90
90
  }
91
+ if (isAccessor) {
92
+ return null;
93
+ }
91
94
  return "observable";
92
95
  }
93
96
  function getPropertyDescriptor$1(obj, key) {
@@ -328,7 +331,7 @@ class ObjectAdministration extends Administration {
328
331
  }
329
332
  getType(key) {
330
333
  let type = this.types.get(key);
331
- if (type === void 0) {
334
+ if (type === void 0 && !this.types.has(key)) {
332
335
  type = getPropertyType(key, this.source);
333
336
  this.types.set(key, type);
334
337
  }
@@ -346,6 +349,9 @@ class ObjectAdministration extends Administration {
346
349
  if (type === "computed") {
347
350
  return resolveNode(this.getComputed(key));
348
351
  }
352
+ if (type === null) {
353
+ return void 0;
354
+ }
349
355
  return resolveNode(this.valuesMap.getOrCreate(key, this.source[key]));
350
356
  }
351
357
  read(key, receiver = this.proxy) {
@@ -357,15 +363,16 @@ class ObjectAdministration extends Administration {
357
363
  this.atom.reportObserved();
358
364
  return Reflect.get(this.source, key, receiver);
359
365
  }
360
- if (key in this.source) {
361
- this.valuesMap.reportObserved(key, this.source[key]);
366
+ if (type === null) {
367
+ return Reflect.get(this.source, key, receiver);
362
368
  }
363
369
  this.atom.reportObserved();
364
370
  if (this.atom.observing) {
365
371
  this.hasMap.reportObserved(key);
366
372
  }
373
+ const value = Reflect.get(this.source, key, receiver);
374
+ this.valuesMap.reportObserved(key, value);
367
375
  if (type === "observable") {
368
- const value = Reflect.get(this.source, key, receiver);
369
376
  const shouldWrap = this.explicitObservables.has(key) || isObservable(value);
370
377
  if (shouldWrap && value && typeof value === "object" && !Object.isFrozen(value)) {
371
378
  const desc = getPropertyDescriptor$1(this.source, key);
@@ -379,13 +386,14 @@ class ObjectAdministration extends Administration {
379
386
  }
380
387
  return value;
381
388
  }
382
- return getAction(
383
- Reflect.get(this.source, key, receiver)
384
- );
389
+ return getAction(value);
385
390
  }
386
391
  explicitObservables = /* @__PURE__ */ new Set();
387
392
  write(key, newValue) {
388
393
  const type = this.getType(key);
394
+ if (type === null) {
395
+ return Reflect.set(this.source, key, newValue, this.proxy);
396
+ }
389
397
  if (type === "computed") {
390
398
  return batch(() => this.set(key, newValue));
391
399
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "r-state-tree",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "reactive state management library",
5
5
  "main": "dist/r-state-tree.cjs",
6
6
  "module": "dist/r-state-tree.js",