varstor 0.0.5 → 0.0.6

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 +16 -10
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -65,10 +65,10 @@ Where:
65
65
 
66
66
  or
67
67
  ```js
68
- Varstor.get (AccessorsCallback (StateAccessors {}) => value) => value
68
+ Varstor.get (AccessorsCallback (StateAccessors {}, Varstor) => value) => value
69
69
  ```
70
70
  Where:
71
- ```AccessorsCallback``` - a function that takes all ```StateAccessors``` in the current namespace, manipulates them, and can return any ```value```, which in turn will be returned from the whole ```get(Callback)``` call.
71
+ ```AccessorsCallback``` - a function that takes all ```StateAccessors``` and a ```Varstor``` instance from the current namespace, manipulates them, and can return any ```value```, which in turn will be returned from the whole ```get(Callback)``` call.
72
72
 
73
73
 
74
74
  Values can be mutated with:
@@ -78,31 +78,38 @@ async Varstor.set (
78
78
  key: value
79
79
  ...
80
80
  }
81
- )
81
+ ) => Varstor
82
82
  ```
83
83
  **Important: values are updated asynchronously; don't assume the script will recognize the change immediately. Instead, make use of ```onChange``` listeners!**
84
84
 
85
85
  To reset all stored values back to defaults:
86
86
  ```js
87
- async Varstor.resetAll ()
87
+ async Varstor.resetAll () => Varstor
88
88
  ```
89
89
 
90
90
  To listen and react to state changes:
91
91
  ```js
92
- Varstor.onChange (Keys[], ChangeCallback(newValue, allValues, previousValue) => void)
92
+ Varstor.onChange (Keys[], ChangeCallback(newValue, allValues, previousValue) => void) => Varstor
93
93
  ```
94
94
  Where:
95
- ```Keys``` (optional) - array of keys of state that you want to listen to
95
+ ```Keys``` - array of keys of the state in the current namespace that you want to listen to
96
96
  ```ChangeCallback``` - function to run when a change happens
97
97
 
98
98
  To remove the listener:
99
99
  ```js
100
- Varstor.removeListener(Keys, ChangeCallback)
100
+ Varstor.removeListener(Keys, ChangeCallback) => Varstor
101
101
  ```
102
- the same parameter usage
102
+ the same parameter usage.
103
+
104
+
105
+
106
+
107
+
108
+ Methods ```.set()```, ```.resetAll()```, ```onChange```, and ```removeListener``` all return a new instance of ```Varstor``` with the same namespace, so command chaining is possible.
109
+ Method ```.get(() => {})``` may return a new ```Varstor``` instance.
103
110
 
104
111
  ## Namespacing
105
- To avoid name collisions, put keys with the same name in different namespaces. You can do that with
112
+ To avoid name collisions, put keys with the same name in different namespaces. You can create a new or get an existing namespace with
106
113
  ```js
107
114
  Varstor.get(String Namespace) => Varstor
108
115
  ```
@@ -118,7 +125,6 @@ Varstor({ key: value }) -> Varstor.set({ key: value })
118
125
  Varstor({}) -> Varstor.resetAll()
119
126
  Varstor([], () => {}) -> Varstor.onChange([], () => {})
120
127
  ```
121
- Each call returns a new instance of ```Varstor```, so the chaining is possible.
122
128
 
123
129
  ## StateAccessor
124
130
  ```StateAccessor``` is a way to manipulate each piece of state individually. It's a function that can be called itself, but also an object with a set of methods:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "varstor",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "State manager for web applications and webextensions, employing reactivity, wrapping, and uniting the usage of different storages' values and common variables into a simple universal interface",
5
5
  "license": "MIT",
6
6
  "author": "Igor Morozov <ismorozs@gmail.com>",