react-globo-state 1.0.6 → 1.1.0
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 +16 -10
- package/global.d.ts +19 -9
- package/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# [React Globo State](https://npmjs.com/package/react-globo-state)
|
|
1
|
+
# [React Globo State - gState.](https://npmjs.com/package/react-globo-state)
|
|
2
2
|
|
|
3
3
|
A react state everywhere, easy and smart ... Only one!
|
|
4
4
|
|
|
@@ -14,7 +14,7 @@ A react state everywhere, easy and smart ... Only one!
|
|
|
14
14
|
|
|
15
15
|
## install
|
|
16
16
|
|
|
17
|
-
```
|
|
17
|
+
```bash
|
|
18
18
|
npm i -D react-globo-state
|
|
19
19
|
```
|
|
20
20
|
|
|
@@ -23,7 +23,7 @@ You use:
|
|
|
23
23
|
```javascript
|
|
24
24
|
|
|
25
25
|
// Import the init
|
|
26
|
-
import
|
|
26
|
+
import "react-globo-state"
|
|
27
27
|
|
|
28
28
|
// start the state
|
|
29
29
|
// * need to be inside your App() only at top and one time...
|
|
@@ -37,14 +37,20 @@ globoState()
|
|
|
37
37
|
## EXAMPLE
|
|
38
38
|
|
|
39
39
|
```js
|
|
40
|
-
import
|
|
40
|
+
import "react-globo-state"
|
|
41
41
|
|
|
42
42
|
const App = () => {
|
|
43
43
|
|
|
44
44
|
// init gState
|
|
45
45
|
globoState()
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
useEffect(
|
|
48
|
+
()=>{
|
|
49
|
+
gState.set("test",{ myNewReactState: "hello world!" })
|
|
50
|
+
},[]
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
return <div>{ JSON.stringify(gState.get("test")) }</div>
|
|
48
54
|
|
|
49
55
|
}
|
|
50
56
|
|
|
@@ -61,21 +67,21 @@ const App = () => {
|
|
|
61
67
|
* Create a state
|
|
62
68
|
* @param name - Name of the gstate
|
|
63
69
|
* @param item - Object, string, number, boolean, array
|
|
64
|
-
* @returns -
|
|
70
|
+
* @returns - true
|
|
65
71
|
*/
|
|
66
72
|
gState.set("name", { test:"test" })
|
|
67
73
|
|
|
68
74
|
/**
|
|
69
75
|
* Get a state
|
|
70
76
|
* @param name - Name of the gstate
|
|
71
|
-
* @returns -
|
|
77
|
+
* @returns - items
|
|
72
78
|
*/
|
|
73
79
|
gState.get("name")
|
|
74
80
|
|
|
75
81
|
/**
|
|
76
82
|
* Remove a state
|
|
77
83
|
* @param name - Name of the gstate
|
|
78
|
-
* @returns -
|
|
84
|
+
* @returns - items
|
|
79
85
|
*/
|
|
80
86
|
gState.remove("name")
|
|
81
87
|
// or
|
|
@@ -83,13 +89,13 @@ const App = () => {
|
|
|
83
89
|
|
|
84
90
|
/**
|
|
85
91
|
* Delete all items from gState
|
|
86
|
-
* @returns -
|
|
92
|
+
* @returns - true
|
|
87
93
|
*/
|
|
88
94
|
gState.deleteAll()
|
|
89
95
|
|
|
90
96
|
/**
|
|
91
97
|
* List all states
|
|
92
|
-
* @returns -
|
|
98
|
+
* @returns - items
|
|
93
99
|
*/
|
|
94
100
|
gState.list()
|
|
95
101
|
|
package/global.d.ts
CHANGED
|
@@ -8,42 +8,52 @@ declare module 'gState'
|
|
|
8
8
|
declare module 'globoState'
|
|
9
9
|
|
|
10
10
|
interface _gState {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Dynamic index signature for additional properties
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
[key: string]: any
|
|
17
|
+
|
|
18
|
+
|
|
11
19
|
/**
|
|
12
20
|
* Create a state
|
|
13
21
|
* @param name - Name of the gstate
|
|
14
22
|
* @param item - Object, string, number, boolean, array
|
|
15
|
-
* @returns -
|
|
23
|
+
* @returns - true
|
|
16
24
|
*/
|
|
17
|
-
set: (name: string, value: string | number | string[] | object) =>
|
|
25
|
+
set: (name: string, value: string | number | string[] | object) => true,
|
|
18
26
|
|
|
19
27
|
/**
|
|
20
28
|
* Get a state
|
|
21
29
|
* @param name - Name of the gstate
|
|
22
|
-
* @returns -
|
|
30
|
+
* @returns - value
|
|
23
31
|
*/
|
|
24
|
-
get: (name: string) =>
|
|
32
|
+
get: (name: string) => value,
|
|
25
33
|
|
|
26
34
|
/**
|
|
27
35
|
* Remove a state
|
|
28
36
|
* @param name - Name of the gstate
|
|
29
|
-
* @returns -
|
|
37
|
+
* @returns - true
|
|
30
38
|
*/
|
|
31
|
-
remove: (name: string) =>
|
|
32
|
-
delete: (name: string) =>
|
|
39
|
+
remove: (name: string) => true,
|
|
40
|
+
delete: (name: string) => true,
|
|
33
41
|
|
|
34
42
|
/**
|
|
35
43
|
* Delete all items from gState
|
|
36
44
|
* @returns - Void
|
|
37
45
|
*/
|
|
38
|
-
deleteAll: () =>
|
|
46
|
+
deleteAll: () => true,
|
|
39
47
|
|
|
40
48
|
/**
|
|
41
49
|
* List all states
|
|
42
50
|
* @returns - Void
|
|
43
51
|
*/
|
|
44
|
-
list: () =>
|
|
52
|
+
list: () => values
|
|
45
53
|
}
|
|
46
54
|
|
|
55
|
+
declare var globoState: () => void
|
|
56
|
+
|
|
47
57
|
declare var gState: _gState
|
|
48
58
|
type gState = _gState
|
|
49
59
|
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useState as
|
|
1
|
+
import{useState as n}from"react";const e={};globalThis.globoState=()=>{const[r,u]=n(null);globalThis.gState={get:t=>{if(t&&t)return r?.[t]?r[t]:null},set:(t,l)=>{if(!(!t||!l))return e[t]=l,u({...e}),!0},remove:t=>{if(t)return delete e[t],u({...e}),!0},delete:t=>{if(t)return gState.remove(t),!0},deleteAll:()=>(u({}),!0),list:()=>r}};
|