chem-rx 0.0.16 → 0.0.18

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
@@ -9,55 +9,88 @@ simplicity. Useable with or without React!
9
9
  [jotai](https://github.com/pmndrs/jotai) or
10
10
  [Recoil](https://github.com/facebookexperimental/Recoil).
11
11
 
12
- Atoms are state containers that take any value - object, array, or primitive.
12
+ Atoms are state containers that take any value - object, array, or primitive. You can create them by simply passing a value into `Atom`.
13
13
 
14
14
  ```
15
15
  import { Atom } from 'chem-rx'
16
16
 
17
+ const data$: BaseAtom = Atom('hello')
18
+ ```
19
+
20
+ ## Primitives
21
+
22
+ There are five primitives in `chem-rx`:
23
+
24
+ 1. BaseAtom
25
+ 2. ArrayAtom
26
+ 3. NullableAtom
27
+ 4. ReadOnlyAtom
28
+ 5. Signal
29
+
30
+ Their traits are self-explanatory, and they are generally automatically created for you, depending on how you create your Atom.
31
+
32
+ In its simplest form, `chem-rx` can be used with BaseAtom and ArrayAtom, giving you a primitive for managing atomic data, but can be composed and split in numerous ways for more advanced use cases.
33
+
34
+ ### BaseAtom & ArrayAtom
35
+
36
+ `BaseAtom` is the fundamental type that everything else extends. It contains the primary functionality for interacting with your Atom data.
37
+
38
+ `ArrayAtom` is exactly as it sounds - an atom that holds an array of values (as opposed to an individual)
39
+
40
+ `Atom` will automatically return you an ArrayAtom or BaseAtom based on what you pass it.
41
+
42
+ ```
17
43
  const number$: BaseAtom = Atom(0)
18
- const string$: BaseAtom = Atom('hello')
19
- const array$: ArrayAtom = Atom(['hello', 'world'])
20
- const object$: ObjectAtom = Atom({ 'hello': 'world', 'world': 'hello' })
44
+ const string$: BaseAtom<string> = Atom('hello')
45
+
46
+ // You can skip the type hint on your variable.
47
+ // This returns a `BaseAtom<{hello: string, world: string}>`
48
+ const object$ = Atom({ 'hello': 'world', 'world': 'hello' })
49
+
50
+ // You can enforce a generic type on your atoms
51
+ // Note the ArrayAtom's generic type holds the item type held in the array.
52
+ const array$: ArrayAtom<string> = Atom<string[]>(['hello', 'world'])
21
53
  ```
22
54
 
23
55
  ### Getting & setting values
24
56
 
25
- `Atom` will automatically return an instance of `BaseAtom`, `ArrayAtom`, or
26
- `ObjectAtom` depending on the input.
57
+ `BaseAtom` offers simple helpers to access and modify your data.
27
58
 
28
59
  ```
29
- // Base Atom
30
- number$.set(2)
31
- number$.value()
32
- // 2
60
+ // Primitive values (BaseAtom)
61
+ number$.next(2)
62
+ number$.value() // 2
63
+
64
+
65
+ // Object values (BaseAtom)
66
+ object$.get('hello') // 'world'
67
+ object$.get('fakeKey') // undefined
68
+ object$.set('hello', 'werld')
69
+ object$.get('hello') // 'werld'
70
+
33
71
 
34
72
  // ArrayAtom
35
73
  array$.push('!')
36
- array$.value()
37
- // ['hello', 'world', '!']
38
- array$.get(1)
39
- // 'world'
74
+ array$.value() // ['hello', 'world', '!']
75
+ array$.get(2) // '!'
76
+ array$.get(3) // undefined
77
+ ```
40
78
 
41
- // ObjectAtom
42
- object$.set('world', 'hi')
43
- object$.value()
44
- // {'hello': 'world', 'world': 'hi'}
79
+ ## Composability & ReadOnlyAtom's
45
80
 
46
- object$.set('sup', 'earth')
47
- // {'hello': 'world', 'world': 'hi', 'sup': 'earth'}
81
+ Atoms are intended to be easily composed, split, and transformed to handle complex data needs through a simple API.
48
82
 
49
- object$.get('world')
50
- // 'hi'
51
- ```
83
+ ### Selecting Atoms (read-only)
84
+
85
+ You can `select` keys on `BaseAtom` and `ArrayAtom` that returns an Atom that wrap the values
86
+ at that key. Any time the original atom changes, your selected atom will automatically update with the latest value.
52
87
 
53
- ### Selecting Atoms
88
+ This can be especially useful for working with different parts of nested Array and Object atoms.
54
89
 
55
- You can select Object and Array atoms to return new Atoms that wrap the values
56
- at that key. This can be useful for working with different parts of nested Array
57
- and Object atoms.
90
+ Atoms created with `select` are **read-only** (`ReadOnlyAtom`). This prevents you from modifying original values that the atom was created from.
58
91
 
59
92
  ```
60
- const nestedData = Atom({
93
+ const students = Atom({
61
94
  stacy: {
62
95
  nickname: "stace",
63
96
  education: {
@@ -67,40 +100,48 @@ const nestedData = Atom({
67
100
  },
68
101
  });
69
102
 
70
- const stacy = nestedData.select("stacy");
71
- console.log(stacy.get('nickname'))
72
- // 'stace'
103
+ // ReadOnlyAtom<{nickname: string, education: ...}>
104
+ const stacy = students.select("stacy");
105
+ const stacySchool = stacy.select("education");
106
+
107
+ stacy.get('nickname') // 'stace'
108
+ stacySchool.get('graduation') // 2014
109
+
110
+ students.set("stacy", {
111
+ nickname: "spacey",
112
+ education: {
113
+ ...students.get("stacy").education,
114
+ graduation: 2015,
115
+ },
116
+ });
117
+
118
+ stacy.get('nickname') // 'spacey'
119
+ stacySchool.get('graduation') // 2015
120
+
121
+ // ERR: Property 'set' does not exist on type ReadOnlyAtom
122
+ stacy.set('nickname', 'stacy')
73
123
 
74
- const stacySchool = nestedData.select("stacy").select("education");
75
- console.log(stacySchool.get('school'))
76
- // 'Penn'
77
124
  ```
78
125
 
79
126
  ### Derived Atoms (read-only)
80
127
 
81
128
  You can derive new Atoms from any existing atoms. Any time the original atoms
82
- change, your derived atoms will automatically update with new values!
129
+ change, your derived atoms will automatically update with new values.
130
+
131
+ Every derived atom is **read-only**. This prevents you from overriding the
132
+ derived output value, since it is automatically derived from another input.
83
133
 
84
134
  ```
85
135
  const atom$ = Atom(3);
86
136
 
87
- // square it
88
137
  const squared$ = atom$.derive((x) => x * x);
89
138
 
90
- // "9"
91
- console.log(squared$.value())
139
+ squared$.value() // "9"
92
140
 
93
- // Update the original value
94
141
  atom$.set(4)
95
142
 
96
- // "16"
97
- console.log(squared$.value())
98
- ```
99
-
100
- Every derived atom is **read-only**. This prevents you from overriding the
101
- derived output value, since it is automatically derived from another input!
143
+ squared$.value() // "16"
102
144
 
103
- ```
104
145
  // ERR: Property 'set' does not exist on type ReadOnlyAtom
105
146
  squared$.set(2)
106
147
  ```
@@ -116,7 +157,7 @@ atom$.set(2)
116
157
 
117
158
  ### Combining Atoms
118
159
 
119
- Multiple atoms can also be **combined** to create brand new atoms!
160
+ Multiple atoms can also be **combined** to create brand new atoms.
120
161
 
121
162
  Here's an example of joining a set of normalized data models
122
163
 
@@ -150,6 +191,8 @@ console.log(mary$.select('pets').value())
150
191
  */
151
192
  ```
152
193
 
194
+ ## Pub/Sub
195
+
153
196
  ### Subscribing to updates
154
197
 
155
198
  Atoms emit values each time they're updated. You can subscribe callbacks to them
@@ -162,8 +205,7 @@ const subscription = atom$.subscribe(val => {
162
205
  console.log("Received value: ", val)
163
206
  })
164
207
 
165
- atom$.set(4)
166
- // "Received value: 4"
208
+ atom$.set(4) // "Received value: 4"
167
209
 
168
210
  // Unsubscribe to clean up
169
211
  subscription.unsubscribe();
@@ -181,8 +223,7 @@ const subscription = signal$.subscribe(() => {
181
223
  console.log("PONG")
182
224
  })
183
225
 
184
- signal$.ping()
185
- // "PONG"
226
+ signal$.ping() // "PONG"
186
227
 
187
228
  // Unsubscribe to clean up
188
229
  subscription.unsubscribe();
@@ -210,8 +251,7 @@ subscription.unsubscribe();
210
251
 
211
252
  `useAtom` automatically updates with new values in your react components.
212
253
 
213
- If you want to update your atoms, you can simply call the same `set`
214
- (Base/ObjectAtom) or `push` (ArrayAtom) methods you would typically use outside
254
+ If you want to update your atoms, you can simply call the same `next`, `set`, or `push` (ArrayAtom) methods you would typically use outside
215
255
  of react.
216
256
 
217
257
  ```
@@ -268,22 +308,17 @@ const CounterPage = ({ countFromServer }) => {
268
308
 
269
309
  There are several suggested "patterns" when using Atoms:
270
310
 
271
- 1. Suffix all atoms with `$` (for readability).
272
- 2. Keep all data management **outside** of your views (e.g, React)
273
- 3. Avoid using `set` and `push` directly from your client components. Instead,
274
- create helper functions (actions)
275
- 4. Name your helper actions as `<atomName>$<actionName>`, to easily see what
276
- atoms are involved.
277
- 5. Name your derived atoms as `<baseAtom>_<derivedValue>$` to easily see which
278
- atoms it derives from.
279
-
280
- ## Common Issues
281
-
282
- Here are some common issues you might run into when starting out.
283
-
284
311
  1. Keep your atoms in separate files to prevent circular dependencies.
285
312
  1. I typically create a new file for every action, so I can easily see the
286
313
  API surface at a glance
314
+ 2. Suffix all atoms with `$` (for readability).
315
+ 3. Keep all data management **outside** of your views (e.g, React)
316
+ 4. Avoid updating atoms (`next`, `set`, and `push`) inside your client components. Instead,
317
+ create an API of helper functions (actions) and call them.
318
+ 5. Name your helper actions as `<atomName>$<actionName>`, to easily see what
319
+ atoms are involved.
320
+ 6. Name your derived atoms as `<baseAtom>_<derivedValue>$` to easily see which
321
+ atoms it derives from.
287
322
 
288
323
  ## Advanced Usage with `rxjs`
289
324
 
@@ -313,6 +348,4 @@ console.log(squared$.value());
313
348
 
314
349
  ## Why...?
315
350
 
316
- This library spawned out of a love for the flexibility and expressiveness of
317
- [rxjs](https://github.com/ReactiveX/rxjs) Observables, and the simplicity of
318
- atomic libraries like [jotai](https://github.com/pmndrs/jotai).
351
+ [`rxjs`](https://github.com/ReactiveX/rxjs) is awesome, and I wanted a framework-agnostic [jotai](https://github.com/pmndrs/jotai)-like solution with a simpler API.
package/dist/Atom.d.ts CHANGED
@@ -35,6 +35,8 @@ export declare class NullableBaseAtom<T> extends BaseAtom<T> {
35
35
  constructor(_value?: T | Observable<T>);
36
36
  get<K extends keyof T>(key: K): (T extends (infer W)[] ? T[number] : T[K]) | undefined;
37
37
  select<K extends keyof T>(key: K): T extends (infer W)[] ? ArrayAtom<W> : NullableBaseAtom<T[K]>;
38
+ next(nextVal: T | null | undefined): void;
39
+ reset(): void;
38
40
  }
39
41
  export declare class ArrayAtom<T> extends BaseAtom<T[]> {
40
42
  constructor(initialValue?: T[]);
@@ -1 +1 @@
1
- {"version":3,"file":"Atom.d.ts","sourceRoot":"","sources":["../src/Atom.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAMf,UAAU,EACV,gBAAgB,EAChB,YAAY,EACb,MAAM,MAAM,CAAC;AAGd,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;KACxB,C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;AAGf,wBAAgB,IAAI,CAAC,CAAC,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;CAAE,EAC1D,KAAK,CAAC,EAAE,CAAC,GACR,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAGvB,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;AAG/C,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAGxD,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;yBAAvD,IAAI"}
package/dist/index.cjs.js CHANGED
@@ -172,6 +172,14 @@ var NullableBaseAtom = /*#__PURE__*/function (_BaseAtom) {
172
172
  // @ts-ignore
173
173
  return _BaseAtom.prototype.select.call(this, key);
174
174
  };
175
+ _proto3.next = function next(nextVal) {
176
+ // @ts-ignore
177
+ _BaseAtom.prototype.next.call(this, nextVal);
178
+ };
179
+ _proto3.reset = function reset() {
180
+ // @ts-ignore
181
+ _BaseAtom.prototype.next.call(this, undefined);
182
+ };
175
183
  return NullableBaseAtom;
176
184
  }(BaseAtom);
177
185
  var ArrayAtom = /*#__PURE__*/function (_BaseAtom2) {
@@ -315,12 +323,12 @@ function useSelectAtom(atom, key) {
315
323
  }
316
324
 
317
325
  var hydratedAtomsSet = new WeakSet();
318
- function hydrateAtoms(values) {
326
+ function hydrateAtoms(values, options) {
319
327
  for (var _iterator = _createForOfIteratorHelperLoose(values), _step; !(_step = _iterator()).done;) {
320
328
  var _step$value = _step.value,
321
329
  atom = _step$value[0],
322
330
  value = _step$value[1];
323
- if (!hydratedAtomsSet.has(atom)) {
331
+ if (!hydratedAtomsSet.has(atom) || options != null && options.force) {
324
332
  hydratedAtomsSet.add(atom);
325
333
  atom._behavior$.next(value);
326
334
  }
@@ -170,6 +170,14 @@ var chemicalRx = (function (exports, rxjs, react) {
170
170
  // @ts-ignore
171
171
  return _BaseAtom.prototype.select.call(this, key);
172
172
  };
173
+ _proto3.next = function next(nextVal) {
174
+ // @ts-ignore
175
+ _BaseAtom.prototype.next.call(this, nextVal);
176
+ };
177
+ _proto3.reset = function reset() {
178
+ // @ts-ignore
179
+ _BaseAtom.prototype.next.call(this, undefined);
180
+ };
173
181
  return NullableBaseAtom;
174
182
  }(BaseAtom);
175
183
  var ArrayAtom = /*#__PURE__*/function (_BaseAtom2) {
@@ -313,12 +321,12 @@ var chemicalRx = (function (exports, rxjs, react) {
313
321
  }
314
322
 
315
323
  var hydratedAtomsSet = new WeakSet();
316
- function hydrateAtoms(values) {
324
+ function hydrateAtoms(values, options) {
317
325
  for (var _iterator = _createForOfIteratorHelperLoose(values), _step; !(_step = _iterator()).done;) {
318
326
  var _step$value = _step.value,
319
327
  atom = _step$value[0],
320
328
  value = _step$value[1];
321
- if (!hydratedAtomsSet.has(atom)) {
329
+ if (!hydratedAtomsSet.has(atom) || options != null && options.force) {
322
330
  hydratedAtomsSet.add(atom);
323
331
  atom._behavior$.next(value);
324
332
  }
package/dist/index.js CHANGED
@@ -106,6 +106,14 @@ class NullableBaseAtom extends BaseAtom {
106
106
  // @ts-ignore
107
107
  return super.select(key);
108
108
  }
109
+ next(nextVal) {
110
+ // @ts-ignore
111
+ super.next(nextVal);
112
+ }
113
+ reset() {
114
+ // @ts-ignore
115
+ super.next(undefined);
116
+ }
109
117
  }
110
118
  class ArrayAtom extends BaseAtom {
111
119
  constructor(initialValue) {
@@ -231,9 +239,9 @@ function useSelectAtom(atom, key) {
231
239
  }
232
240
 
233
241
  const hydratedAtomsSet = new WeakSet();
234
- function hydrateAtoms(values) {
242
+ function hydrateAtoms(values, options) {
235
243
  for (const [atom, value] of values) {
236
- if (!hydratedAtomsSet.has(atom)) {
244
+ if (!hydratedAtomsSet.has(atom) || options != null && options.force) {
237
245
  hydratedAtomsSet.add(atom);
238
246
  atom._behavior$.next(value);
239
247
  }
@@ -1,3 +1,5 @@
1
1
  import { BaseAtom, NullableBaseAtom } from "./Atom";
2
- export declare function hydrateAtoms(values: readonly [NullableBaseAtom<any> | BaseAtom<any>, any][]): void;
2
+ export declare function hydrateAtoms(values: readonly [NullableBaseAtom<any> | BaseAtom<any>, any][], options?: {
3
+ force?: boolean;
4
+ }): void;
3
5
  //# sourceMappingURL=useHydrateAtoms.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useHydrateAtoms.d.ts","sourceRoot":"","sources":["../src/useHydrateAtoms.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAgB,MAAM,QAAQ,CAAC;AAIlE,wBAAgB,YAAY,CAC1B,MAAM,EAAE,SAAS,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,QAQhE"}
1
+ {"version":3,"file":"useHydrateAtoms.d.ts","sourceRoot":"","sources":["../src/useHydrateAtoms.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAgB,MAAM,QAAQ,CAAC;AAIlE,wBAAgB,YAAY,CAC1B,MAAM,EAAE,SAAS,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,EAC/D,OAAO,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,QAQ9B"}
@@ -1,5 +1,5 @@
1
- import { BaseAtom, NullableBaseAtom } from "./Atom";
1
+ import { BaseAtom, NullableBaseAtom, ReadOnlyAtom } from "./Atom";
2
2
  export declare function useSelectAtom<T extends {
3
3
  [key in K]: V;
4
- }, K extends keyof T, V = T[K]>(atom: NullableBaseAtom<T> | BaseAtom<T>, key: K): T[K];
4
+ }, K extends keyof T, V = T[K]>(atom: NullableBaseAtom<T> | BaseAtom<T> | ReadOnlyAtom<T>, key: K): T[K];
5
5
  //# sourceMappingURL=useSelectAtom.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSelectAtom.d.ts","sourceRoot":"","sources":["../src/useSelectAtom.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAEpD,wBAAgB,aAAa,CAC3B,CAAC,SAAS;KACP,GAAG,IAAI,CAAC,GAAG,CAAC;CACd,EACD,CAAC,SAAS,MAAM,CAAC,EACjB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EACR,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAcvD"}
1
+ {"version":3,"file":"useSelectAtom.d.ts","sourceRoot":"","sources":["../src/useSelectAtom.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAElE,wBAAgB,aAAa,CAC3B,CAAC,SACG;KACG,GAAG,IAAI,CAAC,GAAG,CAAC;CACd,EACL,CAAC,SAAS,MAAM,CAAC,EACjB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EACR,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAczE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chem-rx",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "react state primitives powered by rx.js",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/Atom.ts CHANGED
@@ -217,6 +217,16 @@ export class NullableBaseAtom<T> extends BaseAtom<T> {
217
217
  // @ts-ignore
218
218
  return super.select(key);
219
219
  }
220
+
221
+ next(nextVal: T | null | undefined) {
222
+ // @ts-ignore
223
+ super.next(nextVal);
224
+ }
225
+
226
+ reset() {
227
+ // @ts-ignore
228
+ super.next(undefined);
229
+ }
220
230
  }
221
231
 
222
232
  export class ArrayAtom<T> extends BaseAtom<T[]> {
@@ -4,10 +4,11 @@ import { BaseAtom, NullableBaseAtom, ReadOnlyAtom } from "./Atom";
4
4
  const hydratedAtomsSet: WeakSet<ReadOnlyAtom<any>> = new WeakSet();
5
5
 
6
6
  export function hydrateAtoms(
7
- values: readonly [NullableBaseAtom<any> | BaseAtom<any>, any][]
7
+ values: readonly [NullableBaseAtom<any> | BaseAtom<any>, any][],
8
+ options?: { force?: boolean }
8
9
  ) {
9
10
  for (const [atom, value] of values) {
10
- if (!hydratedAtomsSet.has(atom)) {
11
+ if (!hydratedAtomsSet.has(atom) || options?.force) {
11
12
  hydratedAtomsSet.add(atom);
12
13
  atom._behavior$.next(value);
13
14
  }
@@ -1,13 +1,14 @@
1
1
  import { useEffect, useState } from "react";
2
- import { BaseAtom, NullableBaseAtom } from "./Atom";
2
+ import { BaseAtom, NullableBaseAtom, ReadOnlyAtom } from "./Atom";
3
3
 
4
4
  export function useSelectAtom<
5
- T extends {
6
- [key in K]: V;
7
- },
5
+ T extends
6
+ | {
7
+ [key in K]: V;
8
+ },
8
9
  K extends keyof T,
9
10
  V = T[K]
10
- >(atom: NullableBaseAtom<T> | BaseAtom<T>, key: K): T[K] {
11
+ >(atom: NullableBaseAtom<T> | BaseAtom<T> | ReadOnlyAtom<T>, key: K): T[K] {
11
12
  const [value, setValue] = useState<T[K]>(atom.get(key)!);
12
13
 
13
14
  useEffect(() => {
@@ -171,6 +171,8 @@ test("Array Atom get index test", () => {
171
171
  atom.push("second");
172
172
  expect(atom.value().length).toBe(2);
173
173
  expect(atom.get(1)).toBe("second");
174
+
175
+ expect(atom.get(2)).toBe(undefined);
174
176
  });
175
177
 
176
178
  test("Test native pipe", () => {
@@ -415,6 +417,83 @@ test("Test select (nested objects)", () => {
415
417
  expect(stacySchool.get("graduation")).toBe(2014);
416
418
  });
417
419
 
420
+ test("Test parent value when updating child objects ", () => {
421
+ const students = Atom<{
422
+ [key: string]: {
423
+ nickname: string;
424
+ education: {
425
+ school: string;
426
+ graduation: number;
427
+ };
428
+ };
429
+ }>({
430
+ stacy: {
431
+ nickname: "stace",
432
+ education: {
433
+ school: "Penn",
434
+ graduation: 2014,
435
+ },
436
+ },
437
+ annie: {
438
+ nickname: "ann",
439
+ education: {
440
+ school: "Brown",
441
+ graduation: 2015,
442
+ },
443
+ },
444
+ prabhu: {
445
+ nickname: "prab",
446
+ education: {
447
+ school: "MIT",
448
+ graduation: 2016,
449
+ },
450
+ },
451
+ });
452
+ const stacy = students.select("stacy");
453
+ const stacySchool = stacy.select("education");
454
+
455
+ expect(stacy.get("nickname")).toBe("stace");
456
+ expect(students.get("stacy").nickname).toBe("stace");
457
+ expect(stacySchool.get("graduation")).toBe(2014);
458
+
459
+ students.set("stacy", {
460
+ nickname: "spacey",
461
+ education: {
462
+ ...students.get("stacy").education,
463
+ graduation: 2015,
464
+ },
465
+ });
466
+
467
+ expect(stacy.get("nickname")).toBe("spacey");
468
+ expect(students.get("stacy").nickname).toBe("spacey");
469
+ expect(stacySchool.get("graduation")).toBe(2015);
470
+ });
471
+
472
+ test("Test nullable object", () => {
473
+ const nestedData = Atom<{
474
+ [key: string]: {
475
+ nickname: string;
476
+ education: {
477
+ school: string;
478
+ graduation: number;
479
+ };
480
+ };
481
+ }>();
482
+
483
+ // TODO: This errors
484
+ const newVal = nestedData.select("stacy");
485
+
486
+ nestedData.next(undefined);
487
+ const stacy = nestedData.select("stacy");
488
+ const stacySchool = nestedData.select("stacy").select("education");
489
+
490
+ expect(stacy.get("nickname")).toBe(undefined);
491
+ expect(stacySchool.get("school")).toBe(undefined);
492
+ expect(stacySchool.value()).toBe(undefined);
493
+ nestedData.next(null);
494
+ expect(nestedData.value()).toBe(null);
495
+ });
496
+
418
497
  test("Test select nullable object", () => {
419
498
  const seedData = {
420
499
  stacy: {