@fireflysemantics/slice 17.0.3 → 17.0.4
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 +103 -0
- package/package.json +1 -1
package/README.md
CHANGED
@@ -26,6 +26,109 @@ 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
|
+
```
|
37
|
+
import {
|
38
|
+
KeyObsValueReset,
|
39
|
+
ObsValueReset,
|
40
|
+
OStore,
|
41
|
+
OStoreStart,
|
42
|
+
} from '@fireflysemantics/slice';
|
43
|
+
const START: OStoreStart = {
|
44
|
+
K1: { value: 'V1', reset: 'ResetValue' },
|
45
|
+
};
|
46
|
+
interface ISTART extends KeyObsValueReset {
|
47
|
+
K1: ObsValueReset;
|
48
|
+
}
|
49
|
+
let OS: OStore<ISTART> = new OStore(START);
|
50
|
+
|
51
|
+
//============================================
|
52
|
+
// Log a snapshot the initial store value.
|
53
|
+
// This will log
|
54
|
+
// V1
|
55
|
+
//============================================
|
56
|
+
const v1Snapshot: string = OS.snapshot(OS.S.K1);
|
57
|
+
console.log(`The value for the K1 key is ${v1Snapshot}`);
|
58
|
+
|
59
|
+
//============================================
|
60
|
+
// Observe the initial store value.
|
61
|
+
// The subsription will log
|
62
|
+
// V1
|
63
|
+
//============================================
|
64
|
+
OS.S.K1.obs.subscribe((v) => console.log(`The subscribed to value is ${v}`));
|
65
|
+
|
66
|
+
//============================================
|
67
|
+
// Update the initial store value
|
68
|
+
// The subsription will log
|
69
|
+
// New Value
|
70
|
+
//============================================
|
71
|
+
OS.put(OS.S.K1, 'New Value');
|
72
|
+
|
73
|
+
//============================================
|
74
|
+
// Log a count of the number of entries in the
|
75
|
+
// object store.
|
76
|
+
// This will log
|
77
|
+
// 1
|
78
|
+
//============================================
|
79
|
+
const count: number = OS.count();
|
80
|
+
console.log(
|
81
|
+
`The count of the number of entries in the Object Store is ${count}`
|
82
|
+
);
|
83
|
+
|
84
|
+
//============================================
|
85
|
+
// Reset the store
|
86
|
+
// The subsription will log
|
87
|
+
// ResetValue
|
88
|
+
//
|
89
|
+
// However if we had not specified a reset
|
90
|
+
// value it would have logged in value
|
91
|
+
// V1
|
92
|
+
//============================================
|
93
|
+
OS.reset();
|
94
|
+
|
95
|
+
//============================================
|
96
|
+
// Delete the K1 entry
|
97
|
+
// The subsription will log and the snapshot
|
98
|
+
// will also be
|
99
|
+
// undefined
|
100
|
+
//============================================
|
101
|
+
OS.delete(OS.S.K1);
|
102
|
+
const snapshot: string = OS.snapshot(OS.S.K1);
|
103
|
+
console.log(`The deleted value snapshot for the K1 key is ${snapshot}`);
|
104
|
+
|
105
|
+
//============================================
|
106
|
+
// Clear the store. First we will put a new
|
107
|
+
// value back in the store to demonstrate it
|
108
|
+
// being cleared.
|
109
|
+
//============================================
|
110
|
+
//============================================
|
111
|
+
// Update the initial store value
|
112
|
+
// The subsription will log
|
113
|
+
// New Value
|
114
|
+
//============================================
|
115
|
+
OS.put(OS.S.K1, 'V2');
|
116
|
+
|
117
|
+
OS.clear();
|
118
|
+
//============================================
|
119
|
+
// Count the number of values in the store
|
120
|
+
// It will be zero.
|
121
|
+
// The OS.clear() call will remove all the
|
122
|
+
// entries and so the snapshot will be undefined
|
123
|
+
// and the subscribed to value also undefined.
|
124
|
+
// The count will be zero.
|
125
|
+
//============================================
|
126
|
+
console.log(`The count is ${OS.count()}`);
|
127
|
+
console.log(`The snapshot is ${OS.snapshot(OS.S.K1)}`);
|
128
|
+
```
|
129
|
+
|
130
|
+
|
131
|
+
|
29
132
|
# Firefly Semantics Slice Development Center Media and Documentation
|
30
133
|
|
31
134
|
## Concepts
|