@figliolia/galena 2.0.4 → 2.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.
- package/dist/Galena/Guards.d.ts +2 -9
- package/dist/Galena/Guards.js +20 -35
- package/package.json +1 -1
- package/src/Galena/Guards.ts +17 -35
package/dist/Galena/Guards.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare class Guards {
|
|
|
17
17
|
* developers know that they are attempting to manipulate a
|
|
18
18
|
* unit of state that has not yet been initialized
|
|
19
19
|
*/
|
|
20
|
-
protected warnForUndefinedStates
|
|
20
|
+
protected warnForUndefinedStates<T extends Record<string, State<any>>>(name: string, state: T): void;
|
|
21
21
|
/**
|
|
22
22
|
* Guard Duplicate States
|
|
23
23
|
*
|
|
@@ -25,12 +25,5 @@ export declare class Guards {
|
|
|
25
25
|
* more than one state with the same name on a single
|
|
26
26
|
* `Galena` instance
|
|
27
27
|
*/
|
|
28
|
-
protected guardDuplicateStates
|
|
29
|
-
/**
|
|
30
|
-
* Development Guard
|
|
31
|
-
*
|
|
32
|
-
* Wraps a provided function in a check for `process.env.NODE_ENV`
|
|
33
|
-
* equaling "development". Returns the callback
|
|
34
|
-
*/
|
|
35
|
-
private developmentGuard;
|
|
28
|
+
protected guardDuplicateStates<T extends Record<string, State<any>>>(name: string, state: T): void;
|
|
36
29
|
}
|
package/dist/Galena/Guards.js
CHANGED
|
@@ -11,45 +11,30 @@ exports.Guards = void 0;
|
|
|
11
11
|
* of the library
|
|
12
12
|
*/
|
|
13
13
|
class Guards {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
/**
|
|
29
|
-
* Guard Duplicate States
|
|
30
|
-
*
|
|
31
|
-
* Throws an error if a developer attempts to create
|
|
32
|
-
* more than one state with the same name on a single
|
|
33
|
-
* `Galena` instance
|
|
34
|
-
*/
|
|
35
|
-
this.guardDuplicateStates = this.developmentGuard((name, state) => {
|
|
36
|
-
if (name in state) {
|
|
37
|
-
throw new Error(`A unit of state with the name "${name}" already exists on this Galena instance. Please re-name this new unit of state to something unique`);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
14
|
+
/**
|
|
15
|
+
* Warn For Undefined States
|
|
16
|
+
*
|
|
17
|
+
* In Galena, it's normal to lazy initialize a unit of state
|
|
18
|
+
* in attached to a `Galena` instance. This warning lets
|
|
19
|
+
* developers know that they are attempting to manipulate a
|
|
20
|
+
* unit of state that has not yet been initialized
|
|
21
|
+
*/
|
|
22
|
+
warnForUndefinedStates(name, state) {
|
|
23
|
+
if (!(name in state)) {
|
|
24
|
+
console.warn(`A unit of state with the name "${name}" does not yet exist on this Galena instance. If this is expected, you can ignore this warning`);
|
|
25
|
+
}
|
|
40
26
|
}
|
|
41
27
|
/**
|
|
42
|
-
*
|
|
28
|
+
* Guard Duplicate States
|
|
43
29
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
30
|
+
* Throws an error if a developer attempts to create
|
|
31
|
+
* more than one state with the same name on a single
|
|
32
|
+
* `Galena` instance
|
|
46
33
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
};
|
|
34
|
+
guardDuplicateStates(name, state) {
|
|
35
|
+
if (name in state) {
|
|
36
|
+
console.warn(`A unit of state with the name "${name}" already exists on this Galena instance. Please re-name this new unit of state to something unique`);
|
|
37
|
+
}
|
|
53
38
|
}
|
|
54
39
|
}
|
|
55
40
|
exports.Guards = Guards;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@figliolia/galena",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "A performant state management library supporting mutable state, batched updates, middleware and a rich development API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/src/Galena/Guards.ts
CHANGED
|
@@ -18,18 +18,16 @@ export class Guards {
|
|
|
18
18
|
* developers know that they are attempting to manipulate a
|
|
19
19
|
* unit of state that has not yet been initialized
|
|
20
20
|
*/
|
|
21
|
-
protected warnForUndefinedStates
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
);
|
|
30
|
-
}
|
|
21
|
+
protected warnForUndefinedStates<T extends Record<string, State<any>>>(
|
|
22
|
+
name: string,
|
|
23
|
+
state: T
|
|
24
|
+
) {
|
|
25
|
+
if (!(name in state)) {
|
|
26
|
+
console.warn(
|
|
27
|
+
`A unit of state with the name "${name}" does not yet exist on this Galena instance. If this is expected, you can ignore this warning`
|
|
28
|
+
);
|
|
31
29
|
}
|
|
32
|
-
|
|
30
|
+
}
|
|
33
31
|
|
|
34
32
|
/**
|
|
35
33
|
* Guard Duplicate States
|
|
@@ -38,30 +36,14 @@ export class Guards {
|
|
|
38
36
|
* more than one state with the same name on a single
|
|
39
37
|
* `Galena` instance
|
|
40
38
|
*/
|
|
41
|
-
protected guardDuplicateStates
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
);
|
|
50
|
-
}
|
|
39
|
+
protected guardDuplicateStates<T extends Record<string, State<any>>>(
|
|
40
|
+
name: string,
|
|
41
|
+
state: T
|
|
42
|
+
) {
|
|
43
|
+
if (name in state) {
|
|
44
|
+
console.warn(
|
|
45
|
+
`A unit of state with the name "${name}" already exists on this Galena instance. Please re-name this new unit of state to something unique`
|
|
46
|
+
);
|
|
51
47
|
}
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Development Guard
|
|
56
|
-
*
|
|
57
|
-
* Wraps a provided function in a check for `process.env.NODE_ENV`
|
|
58
|
-
* equaling "development". Returns the callback
|
|
59
|
-
*/
|
|
60
|
-
private developmentGuard<F extends (...args: any[]) => void>(guard: F) {
|
|
61
|
-
return (...args: Parameters<F>) => {
|
|
62
|
-
if (process.env.NODE_ENV === "development") {
|
|
63
|
-
guard(...args);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
48
|
}
|
|
67
49
|
}
|