@flexsurfer/reflex 0.1.9 → 0.1.11
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 +3 -4
- package/dist/index.cjs +9 -17
- package/dist/index.mjs +9 -17
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
**re-frame for the JavaScript world**
|
|
6
6
|
|
|
7
|
-
A reactive, functional state management library that brings the elegance and power of ClojureScript's re-frame to JavaScript and React/
|
|
8
|
-
|
|
9
|
-
> ⚠️ **Development Status**: This library is in active development and not yet ready for production use. Perfect for pet projects, experiments, and learning! The community is warmly invited to contribute to the development and improvement of the library, including optimizations for data comparison at different lifecycle stages.
|
|
7
|
+
A reactive, functional state management library that brings the elegance and power of ClojureScript's re-frame to JavaScript and React/ReactNative applications.
|
|
10
8
|
|
|
11
9
|
[](https://opensource.org/licenses/MIT)
|
|
12
10
|
[](https://www.npmjs.com/package/@flexsurfer/reflex)
|
|
@@ -16,11 +14,12 @@ A reactive, functional state management library that brings the elegance and pow
|
|
|
16
14
|
|
|
17
15
|
## ✨ Why Reflex?
|
|
18
16
|
|
|
19
|
-
After many years of building applications with re-frame in the ClojureScript world, I wanted to bring the same architectural elegance to the JavaScript/TypeScript ecosystem. Reflex is not just another state management library—it's a battle-tested pattern that promotes:
|
|
17
|
+
After many years of building applications with re-frame in the ClojureScript world, I wanted to bring the same architectural elegance to the JavaScript/TypeScript ecosystem. Reflex is not just another state management library—it's a **battle-tested** pattern that promotes:
|
|
20
18
|
|
|
21
19
|
🎯 **Predictable State Management** - Unidirectional data flow with pure functions
|
|
22
20
|
🧩 **Composable Architecture** - Build complex apps from simple, reusable pieces
|
|
23
21
|
🔄 **Reactive Subscriptions** - UI automatically updates when state changes
|
|
22
|
+
🌐 **Multi-Platform Support** - With effects separation, it's super easy to support multiple platforms with the same codebase, including web, mobile, and desktop
|
|
24
23
|
⚡ **Interceptor Pattern** - Powerful middleware system for cross-cutting concerns
|
|
25
24
|
🛡️ **Type Safety** - Full TypeScript support with excellent IDE experience
|
|
26
25
|
🧪 **Testability** - Pure functions make testing straightforward and reliable
|
package/dist/index.cjs
CHANGED
|
@@ -834,7 +834,6 @@ var Reaction = class _Reaction {
|
|
|
834
834
|
version = 0;
|
|
835
835
|
depsVersions = [];
|
|
836
836
|
subVector;
|
|
837
|
-
componentName;
|
|
838
837
|
constructor(computeFn, deps) {
|
|
839
838
|
this.computeFn = computeFn;
|
|
840
839
|
this.deps = deps;
|
|
@@ -851,10 +850,10 @@ var Reaction = class _Reaction {
|
|
|
851
850
|
this.recomputeIfNeeded(notifyWatchers);
|
|
852
851
|
return [this.value, this.version];
|
|
853
852
|
}
|
|
854
|
-
watch(callback) {
|
|
855
|
-
const idx = this.watchers.
|
|
853
|
+
watch(callback, componentName = "react component") {
|
|
854
|
+
const idx = this.watchers.findIndex((w) => w.callback === callback);
|
|
856
855
|
if (idx === -1) {
|
|
857
|
-
this.watchers.push(callback);
|
|
856
|
+
this.watchers.push({ callback, componentName });
|
|
858
857
|
if (this.deps) {
|
|
859
858
|
for (const d of this.deps)
|
|
860
859
|
d.ensureAliveWith(this);
|
|
@@ -862,7 +861,7 @@ var Reaction = class _Reaction {
|
|
|
862
861
|
}
|
|
863
862
|
}
|
|
864
863
|
unwatch(fn) {
|
|
865
|
-
const idx = this.watchers.
|
|
864
|
+
const idx = this.watchers.findIndex((w) => w.callback === fn);
|
|
866
865
|
if (idx !== -1) {
|
|
867
866
|
this.watchers.splice(idx, 1);
|
|
868
867
|
if (this.watchers.length === 0) {
|
|
@@ -926,11 +925,10 @@ var Reaction = class _Reaction {
|
|
|
926
925
|
withTrace(
|
|
927
926
|
{
|
|
928
927
|
opType: "render",
|
|
929
|
-
operation:
|
|
930
|
-
tags: this.componentName ? { componentName: this.componentName } : {}
|
|
928
|
+
operation: w.componentName
|
|
931
929
|
},
|
|
932
930
|
() => {
|
|
933
|
-
w(this.value);
|
|
931
|
+
w.callback(this.value);
|
|
934
932
|
}
|
|
935
933
|
);
|
|
936
934
|
} catch (error) {
|
|
@@ -1014,9 +1012,6 @@ var Reaction = class _Reaction {
|
|
|
1014
1012
|
get isRoot() {
|
|
1015
1013
|
return this.deps === void 0 || this.deps.length === 0;
|
|
1016
1014
|
}
|
|
1017
|
-
setComponentName(componentName) {
|
|
1018
|
-
this.componentName = componentName;
|
|
1019
|
-
}
|
|
1020
1015
|
};
|
|
1021
1016
|
|
|
1022
1017
|
// src/subs.ts
|
|
@@ -1044,8 +1039,6 @@ function getOrCreateReaction(subVector) {
|
|
|
1044
1039
|
consoleLog("error", `[reflex] no sub handler registered for: ${subId}`);
|
|
1045
1040
|
return null;
|
|
1046
1041
|
}
|
|
1047
|
-
withTrace({ operation: subVector[0], opType: KIND4, tags: { queryV: subVector } }, () => {
|
|
1048
|
-
});
|
|
1049
1042
|
const computeFn = getHandler(KIND4, subId);
|
|
1050
1043
|
const subVectorKey = JSON.stringify(subVector);
|
|
1051
1044
|
const existingReaction = getReaction(subVectorKey);
|
|
@@ -1053,7 +1046,8 @@ function getOrCreateReaction(subVector) {
|
|
|
1053
1046
|
mergeTrace({ tags: { "cached?": true, reaction: existingReaction.getId() } });
|
|
1054
1047
|
return existingReaction;
|
|
1055
1048
|
}
|
|
1056
|
-
|
|
1049
|
+
withTrace({ operation: subVector[0], opType: "sub/create", tags: { queryV: subVector } }, () => {
|
|
1050
|
+
});
|
|
1057
1051
|
const params = subVector.length > 1 ? subVector.slice(1) : [];
|
|
1058
1052
|
const depsFn = getHandler(KIND_DEPS, subId);
|
|
1059
1053
|
const depsVectors = depsFn(...params);
|
|
@@ -1070,7 +1064,6 @@ function getOrCreateReaction(subVector) {
|
|
|
1070
1064
|
},
|
|
1071
1065
|
depsReactions
|
|
1072
1066
|
);
|
|
1073
|
-
mergeTrace({ reaction: reaction.getId() });
|
|
1074
1067
|
reaction.setId(subVectorKey);
|
|
1075
1068
|
reaction.setSubVector(subVector);
|
|
1076
1069
|
setReaction(subVectorKey, reaction);
|
|
@@ -1121,8 +1114,7 @@ function useSubscription(subVector, componentName = "react component") {
|
|
|
1121
1114
|
const reaction = getOrCreateReaction(subVector);
|
|
1122
1115
|
if (!reaction)
|
|
1123
1116
|
return;
|
|
1124
|
-
reaction.
|
|
1125
|
-
reaction.watch(setVal);
|
|
1117
|
+
reaction.watch(setVal, componentName);
|
|
1126
1118
|
return () => {
|
|
1127
1119
|
reaction.unwatch(setVal);
|
|
1128
1120
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -766,7 +766,6 @@ var Reaction = class _Reaction {
|
|
|
766
766
|
version = 0;
|
|
767
767
|
depsVersions = [];
|
|
768
768
|
subVector;
|
|
769
|
-
componentName;
|
|
770
769
|
constructor(computeFn, deps) {
|
|
771
770
|
this.computeFn = computeFn;
|
|
772
771
|
this.deps = deps;
|
|
@@ -783,10 +782,10 @@ var Reaction = class _Reaction {
|
|
|
783
782
|
this.recomputeIfNeeded(notifyWatchers);
|
|
784
783
|
return [this.value, this.version];
|
|
785
784
|
}
|
|
786
|
-
watch(callback) {
|
|
787
|
-
const idx = this.watchers.
|
|
785
|
+
watch(callback, componentName = "react component") {
|
|
786
|
+
const idx = this.watchers.findIndex((w) => w.callback === callback);
|
|
788
787
|
if (idx === -1) {
|
|
789
|
-
this.watchers.push(callback);
|
|
788
|
+
this.watchers.push({ callback, componentName });
|
|
790
789
|
if (this.deps) {
|
|
791
790
|
for (const d of this.deps)
|
|
792
791
|
d.ensureAliveWith(this);
|
|
@@ -794,7 +793,7 @@ var Reaction = class _Reaction {
|
|
|
794
793
|
}
|
|
795
794
|
}
|
|
796
795
|
unwatch(fn) {
|
|
797
|
-
const idx = this.watchers.
|
|
796
|
+
const idx = this.watchers.findIndex((w) => w.callback === fn);
|
|
798
797
|
if (idx !== -1) {
|
|
799
798
|
this.watchers.splice(idx, 1);
|
|
800
799
|
if (this.watchers.length === 0) {
|
|
@@ -858,11 +857,10 @@ var Reaction = class _Reaction {
|
|
|
858
857
|
withTrace(
|
|
859
858
|
{
|
|
860
859
|
opType: "render",
|
|
861
|
-
operation:
|
|
862
|
-
tags: this.componentName ? { componentName: this.componentName } : {}
|
|
860
|
+
operation: w.componentName
|
|
863
861
|
},
|
|
864
862
|
() => {
|
|
865
|
-
w(this.value);
|
|
863
|
+
w.callback(this.value);
|
|
866
864
|
}
|
|
867
865
|
);
|
|
868
866
|
} catch (error) {
|
|
@@ -946,9 +944,6 @@ var Reaction = class _Reaction {
|
|
|
946
944
|
get isRoot() {
|
|
947
945
|
return this.deps === void 0 || this.deps.length === 0;
|
|
948
946
|
}
|
|
949
|
-
setComponentName(componentName) {
|
|
950
|
-
this.componentName = componentName;
|
|
951
|
-
}
|
|
952
947
|
};
|
|
953
948
|
|
|
954
949
|
// src/subs.ts
|
|
@@ -976,8 +971,6 @@ function getOrCreateReaction(subVector) {
|
|
|
976
971
|
consoleLog("error", `[reflex] no sub handler registered for: ${subId}`);
|
|
977
972
|
return null;
|
|
978
973
|
}
|
|
979
|
-
withTrace({ operation: subVector[0], opType: KIND4, tags: { queryV: subVector } }, () => {
|
|
980
|
-
});
|
|
981
974
|
const computeFn = getHandler(KIND4, subId);
|
|
982
975
|
const subVectorKey = JSON.stringify(subVector);
|
|
983
976
|
const existingReaction = getReaction(subVectorKey);
|
|
@@ -985,7 +978,8 @@ function getOrCreateReaction(subVector) {
|
|
|
985
978
|
mergeTrace({ tags: { "cached?": true, reaction: existingReaction.getId() } });
|
|
986
979
|
return existingReaction;
|
|
987
980
|
}
|
|
988
|
-
|
|
981
|
+
withTrace({ operation: subVector[0], opType: "sub/create", tags: { queryV: subVector } }, () => {
|
|
982
|
+
});
|
|
989
983
|
const params = subVector.length > 1 ? subVector.slice(1) : [];
|
|
990
984
|
const depsFn = getHandler(KIND_DEPS, subId);
|
|
991
985
|
const depsVectors = depsFn(...params);
|
|
@@ -1002,7 +996,6 @@ function getOrCreateReaction(subVector) {
|
|
|
1002
996
|
},
|
|
1003
997
|
depsReactions
|
|
1004
998
|
);
|
|
1005
|
-
mergeTrace({ reaction: reaction.getId() });
|
|
1006
999
|
reaction.setId(subVectorKey);
|
|
1007
1000
|
reaction.setSubVector(subVector);
|
|
1008
1001
|
setReaction(subVectorKey, reaction);
|
|
@@ -1053,8 +1046,7 @@ function useSubscription(subVector, componentName = "react component") {
|
|
|
1053
1046
|
const reaction = getOrCreateReaction(subVector);
|
|
1054
1047
|
if (!reaction)
|
|
1055
1048
|
return;
|
|
1056
|
-
reaction.
|
|
1057
|
-
reaction.watch(setVal);
|
|
1049
|
+
reaction.watch(setVal, componentName);
|
|
1058
1050
|
return () => {
|
|
1059
1051
|
reaction.unwatch(setVal);
|
|
1060
1052
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flexsurfer/reflex",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "https://github.com/flexsurfer/reflex.git"
|
|
7
|
+
"url": "git+https://github.com/flexsurfer/reflex.git"
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
10
|
"main": "dist/index.cjs",
|
|
@@ -68,4 +68,4 @@
|
|
|
68
68
|
"pubsub",
|
|
69
69
|
"handler"
|
|
70
70
|
]
|
|
71
|
-
}
|
|
71
|
+
}
|