@flexsurfer/reflex 0.1.10 → 0.1.12

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 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/RN applications.
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
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
12
10
  [![NPM Version](https://img.shields.io/npm/v/%40flexsurfer%2Freflex)](https://www.npmjs.com/package/@flexsurfer/reflex)
@@ -16,11 +14,14 @@ 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
23
+ 🤖 **AI Friendly** - Reviewing AI-generated changes is easier because all logic is expressed through pure, isolated functions, making each change understandable, verifiable, and deterministic.
24
+ 🛠️ **Integrated DevTools** - Reflex-devtools provides deep visibility into your app’s state, events, and subscriptions in real time, forming a powerful combo with Reflex for effective development and debugging.
24
25
  ⚡ **Interceptor Pattern** - Powerful middleware system for cross-cutting concerns
25
26
  🛡️ **Type Safety** - Full TypeScript support with excellent IDE experience
26
27
  🧪 **Testability** - Pure functions make testing straightforward and reliable
@@ -29,6 +30,9 @@ After many years of building applications with re-frame in the ClojureScript wor
29
30
 
30
31
  ```bash
31
32
  npm install @flexsurfer/reflex
33
+ npm install --save-dev @flexsurfer/reflex-devtools
34
+
35
+ npx reflex-devtools
32
36
  ```
33
37
 
34
38
  ### Basic Example
@@ -39,8 +43,13 @@ import {
39
43
  regEvent,
40
44
  regSub,
41
45
  dispatch,
42
- useSubscription
46
+ useSubscription,
47
+ enableTracing
43
48
  } from '@flexsurfer/reflex';
49
+ import { enableDevtools } from '@flexsurfer/reflex-devtools'
50
+
51
+ enableTracing()
52
+ enableDevtools();
44
53
 
45
54
  // Initialize your app database
46
55
  initAppDb({ counter: 0 });
package/dist/index.cjs CHANGED
@@ -627,9 +627,7 @@ function resetTracing() {
627
627
  }
628
628
  function registerTraceCb(key, cb) {
629
629
  if (!traceEnabled) {
630
- console.warn(
631
- "Tracing is not enabled; call enableTracing() before registering callbacks"
632
- );
630
+ consoleLog("warn", "[reflex] [trace] Tracing is not enabled; call enableTracing() before registering callbacks");
633
631
  return;
634
632
  }
635
633
  traceCbs.set(key, cb);
@@ -645,7 +643,7 @@ function scheduleFlush() {
645
643
  try {
646
644
  cb(batch);
647
645
  } catch (e) {
648
- console.error("Error in trace callback", e);
646
+ consoleLog("warn", "Error in trace callback", e);
649
647
  }
650
648
  }
651
649
  }, DEBOUNCE_TIME);
@@ -971,7 +969,7 @@ var Reaction = class _Reaction {
971
969
  operation: this.subVector?.[0] ?? "",
972
970
  opType: "sub/dispose",
973
971
  tags: {
974
- subVector: this.subVector,
972
+ queryV: this.subVector,
975
973
  reaction: this.id
976
974
  }
977
975
  },
@@ -1039,8 +1037,6 @@ function getOrCreateReaction(subVector) {
1039
1037
  consoleLog("error", `[reflex] no sub handler registered for: ${subId}`);
1040
1038
  return null;
1041
1039
  }
1042
- withTrace({ operation: subVector[0], opType: KIND4, tags: { queryV: subVector } }, () => {
1043
- });
1044
1040
  const computeFn = getHandler(KIND4, subId);
1045
1041
  const subVectorKey = JSON.stringify(subVector);
1046
1042
  const existingReaction = getReaction(subVectorKey);
@@ -1048,7 +1044,8 @@ function getOrCreateReaction(subVector) {
1048
1044
  mergeTrace({ tags: { "cached?": true, reaction: existingReaction.getId() } });
1049
1045
  return existingReaction;
1050
1046
  }
1051
- mergeTrace({ tags: { "cached?": false } });
1047
+ withTrace({ operation: subVector[0], opType: "sub/create", tags: { queryV: subVector } }, () => {
1048
+ });
1052
1049
  const params = subVector.length > 1 ? subVector.slice(1) : [];
1053
1050
  const depsFn = getHandler(KIND_DEPS, subId);
1054
1051
  const depsVectors = depsFn(...params);
@@ -1065,7 +1062,6 @@ function getOrCreateReaction(subVector) {
1065
1062
  },
1066
1063
  depsReactions
1067
1064
  );
1068
- mergeTrace({ reaction: reaction.getId() });
1069
1065
  reaction.setId(subVectorKey);
1070
1066
  reaction.setSubVector(subVector);
1071
1067
  setReaction(subVectorKey, reaction);
package/dist/index.mjs CHANGED
@@ -559,9 +559,7 @@ function resetTracing() {
559
559
  }
560
560
  function registerTraceCb(key, cb) {
561
561
  if (!traceEnabled) {
562
- console.warn(
563
- "Tracing is not enabled; call enableTracing() before registering callbacks"
564
- );
562
+ consoleLog("warn", "[reflex] [trace] Tracing is not enabled; call enableTracing() before registering callbacks");
565
563
  return;
566
564
  }
567
565
  traceCbs.set(key, cb);
@@ -577,7 +575,7 @@ function scheduleFlush() {
577
575
  try {
578
576
  cb(batch);
579
577
  } catch (e) {
580
- console.error("Error in trace callback", e);
578
+ consoleLog("warn", "Error in trace callback", e);
581
579
  }
582
580
  }
583
581
  }, DEBOUNCE_TIME);
@@ -903,7 +901,7 @@ var Reaction = class _Reaction {
903
901
  operation: this.subVector?.[0] ?? "",
904
902
  opType: "sub/dispose",
905
903
  tags: {
906
- subVector: this.subVector,
904
+ queryV: this.subVector,
907
905
  reaction: this.id
908
906
  }
909
907
  },
@@ -971,8 +969,6 @@ function getOrCreateReaction(subVector) {
971
969
  consoleLog("error", `[reflex] no sub handler registered for: ${subId}`);
972
970
  return null;
973
971
  }
974
- withTrace({ operation: subVector[0], opType: KIND4, tags: { queryV: subVector } }, () => {
975
- });
976
972
  const computeFn = getHandler(KIND4, subId);
977
973
  const subVectorKey = JSON.stringify(subVector);
978
974
  const existingReaction = getReaction(subVectorKey);
@@ -980,7 +976,8 @@ function getOrCreateReaction(subVector) {
980
976
  mergeTrace({ tags: { "cached?": true, reaction: existingReaction.getId() } });
981
977
  return existingReaction;
982
978
  }
983
- mergeTrace({ tags: { "cached?": false } });
979
+ withTrace({ operation: subVector[0], opType: "sub/create", tags: { queryV: subVector } }, () => {
980
+ });
984
981
  const params = subVector.length > 1 ? subVector.slice(1) : [];
985
982
  const depsFn = getHandler(KIND_DEPS, subId);
986
983
  const depsVectors = depsFn(...params);
@@ -997,7 +994,6 @@ function getOrCreateReaction(subVector) {
997
994
  },
998
995
  depsReactions
999
996
  );
1000
- mergeTrace({ reaction: reaction.getId() });
1001
997
  reaction.setId(subVectorKey);
1002
998
  reaction.setSubVector(subVector);
1003
999
  setReaction(subVectorKey, reaction);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flexsurfer/reflex",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",