@fireflysemantics/slice 17.0.3 → 17.0.5

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.
Files changed (2) hide show
  1. package/README.md +105 -0
  2. package/package.json +3 -2
package/README.md CHANGED
@@ -26,6 +26,111 @@ For Angular 17 run.
26
26
  npm i @fireflysemantics/slice@lastest nanoid
27
27
  ```
28
28
 
29
+ # Usage
30
+
31
+ ## Object Store Core Use Cases
32
+
33
+ [Here is a link to the Stackblitz Demo](https://stackblitz.com/edit/typescript-9snt67?file=index.ts)
34
+ containing all of the below examples.
35
+
36
+ In this demo we are using simple `string` values, but we could have used objects or essentially anything that can be referenced by Javascript.
37
+
38
+ ```
39
+ import {
40
+ KeyObsValueReset,
41
+ ObsValueReset,
42
+ OStore,
43
+ OStoreStart,
44
+ } from '@fireflysemantics/slice';
45
+ const START: OStoreStart = {
46
+ K1: { value: 'V1', reset: 'ResetValue' },
47
+ };
48
+ interface ISTART extends KeyObsValueReset {
49
+ K1: ObsValueReset;
50
+ }
51
+ let OS: OStore<ISTART> = new OStore(START);
52
+
53
+ //============================================
54
+ // Log a snapshot the initial store value.
55
+ // This will log
56
+ // V1
57
+ //============================================
58
+ const v1Snapshot: string = OS.snapshot(OS.S.K1);
59
+ console.log(`The value for the K1 key is ${v1Snapshot}`);
60
+
61
+ //============================================
62
+ // Observe the initial store value.
63
+ // The subsription will log
64
+ // V1
65
+ //============================================
66
+ OS.S.K1.obs.subscribe((v) => console.log(`The subscribed to value is ${v}`));
67
+
68
+ //============================================
69
+ // Update the initial store value
70
+ // The subsription will log
71
+ // New Value
72
+ //============================================
73
+ OS.put(OS.S.K1, 'New Value');
74
+
75
+ //============================================
76
+ // Log a count of the number of entries in the
77
+ // object store.
78
+ // This will log
79
+ // 1
80
+ //============================================
81
+ const count: number = OS.count();
82
+ console.log(
83
+ `The count of the number of entries in the Object Store is ${count}`
84
+ );
85
+
86
+ //============================================
87
+ // Reset the store
88
+ // The subsription will log
89
+ // ResetValue
90
+ //
91
+ // However if we had not specified a reset
92
+ // value it would have logged in value
93
+ // V1
94
+ //============================================
95
+ OS.reset();
96
+
97
+ //============================================
98
+ // Delete the K1 entry
99
+ // The subsription will log and the snapshot
100
+ // will also be
101
+ // undefined
102
+ //============================================
103
+ OS.delete(OS.S.K1);
104
+ const snapshot: string = OS.snapshot(OS.S.K1);
105
+ console.log(`The deleted value snapshot for the K1 key is ${snapshot}`);
106
+
107
+ //============================================
108
+ // Clear the store. First we will put a new
109
+ // value back in the store to demonstrate it
110
+ // being cleared.
111
+ //============================================
112
+ //============================================
113
+ // Update the initial store value
114
+ // The subsription will log
115
+ // New Value
116
+ //============================================
117
+ OS.put(OS.S.K1, 'V2');
118
+
119
+ OS.clear();
120
+ //============================================
121
+ // Count the number of values in the store
122
+ // It will be zero.
123
+ // The OS.clear() call will remove all the
124
+ // entries and so the snapshot will be undefined
125
+ // and the subscribed to value also undefined.
126
+ // The count will be zero.
127
+ //============================================
128
+ console.log(`The count is ${OS.count()}`);
129
+ console.log(`The snapshot is ${OS.snapshot(OS.S.K1)}`);
130
+ ```
131
+
132
+
133
+
29
134
  # Firefly Semantics Slice Development Center Media and Documentation
30
135
 
31
136
  ## Concepts
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@fireflysemantics/slice",
3
- "version": "17.0.3",
3
+ "version": "17.0.5",
4
4
  "peerDependencies": {
5
5
  "nanoid": "^5.0.4",
6
- "@types/nanoid": "*"
6
+ "@types/nanoid": "*",
7
+ "rxjs": "*"
7
8
  },
8
9
  "author": "Ole Ersoy",
9
10
  "license": "MIT",