funkophile 0.2.2 → 0.2.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/dist/esm/funkophileHelpers.js +15 -4
- package/dist/esm/index.js +9 -0
- package/funkophileHelpers.ts +22 -10
- package/index.ts +3 -0
- package/package.json +1 -1
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { createSelector } from "reselect";
|
|
2
2
|
export const contentsOfFiles = (selector) => {
|
|
3
3
|
return createSelector([selector], (selected) => {
|
|
4
|
-
|
|
4
|
+
if (!selected)
|
|
5
|
+
return "";
|
|
6
|
+
return Object.keys(selected).reduce((mm, k) => mm + (selected[k] || ""), "");
|
|
5
7
|
});
|
|
6
8
|
};
|
|
7
9
|
export const contentOfFile = (selector) => {
|
|
8
10
|
return createSelector([selector], (selected) => {
|
|
9
11
|
try {
|
|
10
|
-
|
|
12
|
+
if (!selected)
|
|
13
|
+
return "";
|
|
14
|
+
const keys = Object.keys(selected);
|
|
15
|
+
if (keys.length === 0)
|
|
16
|
+
return "";
|
|
17
|
+
return selected[keys[0]] || "";
|
|
11
18
|
}
|
|
12
19
|
catch (e) {
|
|
13
20
|
console.error("error", e);
|
|
@@ -19,19 +26,23 @@ export const contentOfFile = (selector) => {
|
|
|
19
26
|
};
|
|
20
27
|
export const srcAndContentOfFile = (selector, key) => {
|
|
21
28
|
return createSelector([selector], (selected) => {
|
|
29
|
+
if (!selected)
|
|
30
|
+
return { src: key, content: "" };
|
|
22
31
|
return {
|
|
23
32
|
src: key,
|
|
24
|
-
content: selected[key],
|
|
33
|
+
content: selected[key] || "",
|
|
25
34
|
};
|
|
26
35
|
});
|
|
27
36
|
};
|
|
28
37
|
export const srcAndContentOfFiles = (selector) => {
|
|
29
38
|
return createSelector([selector], (selected) => {
|
|
39
|
+
if (!selected)
|
|
40
|
+
return [];
|
|
30
41
|
const keys = Object.keys(selected);
|
|
31
42
|
return keys.map((key) => {
|
|
32
43
|
return {
|
|
33
44
|
src: key,
|
|
34
|
-
content: selected[key],
|
|
45
|
+
content: selected[key] || "",
|
|
35
46
|
};
|
|
36
47
|
});
|
|
37
48
|
});
|
package/dist/esm/index.js
CHANGED
|
@@ -77,6 +77,15 @@ export default (funkophileConfig) => {
|
|
|
77
77
|
...funkophileConfig.initialState,
|
|
78
78
|
timestamp: Date.now(),
|
|
79
79
|
}, action) => {
|
|
80
|
+
// Ensure state is always an object
|
|
81
|
+
if (!state) {
|
|
82
|
+
throw new Error("State is undefined");
|
|
83
|
+
// state = {
|
|
84
|
+
// initialLoad: true,
|
|
85
|
+
// ...funkophileConfig.initialState,
|
|
86
|
+
// timestamp: Date.now(),
|
|
87
|
+
// };
|
|
88
|
+
}
|
|
80
89
|
// console.log("\u001b[7m\u001b[35m ||| Redux recieved action \u001b[0m", action.type)
|
|
81
90
|
if (!action.type.includes("@@redux")) {
|
|
82
91
|
if (action.type === INITIALIZE) {
|
package/funkophileHelpers.ts
CHANGED
|
@@ -2,25 +2,34 @@ import { createSelector } from "reselect";
|
|
|
2
2
|
|
|
3
3
|
export const contentsOfFiles = (selector) => {
|
|
4
4
|
return createSelector([selector], (selected) => {
|
|
5
|
-
|
|
5
|
+
if (selected === undefined || selected === null) {
|
|
6
|
+
throw new Error(`contentsOfFiles: selected is ${selected}. Make sure the selector is pointing to valid state.`);
|
|
7
|
+
}
|
|
8
|
+
return Object.keys(selected).reduce((mm, k) => mm + (selected[k] || ""), "");
|
|
6
9
|
});
|
|
7
10
|
};
|
|
8
11
|
|
|
9
12
|
export const contentOfFile = (selector) => {
|
|
10
13
|
return createSelector([selector], (selected) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
process.exit(-1)
|
|
14
|
+
if (selected === undefined || selected === null) {
|
|
15
|
+
throw new Error(`contentOfFile: selected is ${selected}. Make sure the selector is pointing to valid state.`);
|
|
16
|
+
}
|
|
17
|
+
const keys = Object.keys(selected);
|
|
18
|
+
if (keys.length === 0) {
|
|
19
|
+
throw new Error(`contentOfFile: selected object is empty. No files found.`);
|
|
18
20
|
}
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
+
return selected[keys[0]] || "";
|
|
22
|
+
});
|
|
23
|
+
};
|
|
21
24
|
|
|
22
25
|
export const srcAndContentOfFile = (selector, key: string) => {
|
|
23
26
|
return createSelector([selector], (selected) => {
|
|
27
|
+
if (selected === undefined || selected === null) {
|
|
28
|
+
throw new Error(`srcAndContentOfFile: selected is ${selected}. Make sure the selector is pointing to valid state.`);
|
|
29
|
+
}
|
|
30
|
+
if (selected[key] === undefined) {
|
|
31
|
+
throw new Error(`srcAndContentOfFile: key "${key}" not found in selected object. Available keys: ${Object.keys(selected).join(', ')}`);
|
|
32
|
+
}
|
|
24
33
|
return {
|
|
25
34
|
src: key,
|
|
26
35
|
content: selected[key],
|
|
@@ -30,6 +39,9 @@ export const srcAndContentOfFile = (selector, key: string) => {
|
|
|
30
39
|
|
|
31
40
|
export const srcAndContentOfFiles = (selector) => {
|
|
32
41
|
return createSelector([selector], (selected) => {
|
|
42
|
+
if (selected === undefined || selected === null) {
|
|
43
|
+
throw new Error(`srcAndContentOfFiles: selected is ${selected}. Make sure the selector is pointing to valid state.`);
|
|
44
|
+
}
|
|
33
45
|
const keys = Object.keys(selected);
|
|
34
46
|
return keys.map((key) => {
|
|
35
47
|
return {
|
package/index.ts
CHANGED
|
@@ -123,6 +123,9 @@ export default (funkophileConfig: {
|
|
|
123
123
|
},
|
|
124
124
|
action,
|
|
125
125
|
) => {
|
|
126
|
+
if (state === undefined) {
|
|
127
|
+
throw new Error("Redux state is undefined. This should never happen.");
|
|
128
|
+
}
|
|
126
129
|
// console.log("\u001b[7m\u001b[35m ||| Redux recieved action \u001b[0m", action.type)
|
|
127
130
|
if (!action.type.includes("@@redux")) {
|
|
128
131
|
if (action.type === INITIALIZE) {
|