repos / starfx

supercharged async flow control library.
git clone https://github.com/neurosnap/starfx.git

commit
3dbdd21
parent
6ca0a85
author
Eric Bower
date
2024-07-30 19:13:52 +0000 UTC
docs: readme
1 files changed,  +59, -0
M README.md
+59, -0
 1@@ -4,4 +4,63 @@
 2 
 3 A micro-mvc framework for react apps.
 4 
 5+If we think in terms of MVC, if `react` is the **View**, then `starfx` is the
 6+**Model** and **Controller**.
 7+
 8 [Get started](https://starfx.bower.sh)
 9+
10+Features:
11+
12+- A powerful middleware system to fetch API data
13+- An immutable and reactive data store
14+- A task tree side-effect system for handling complex business logic using
15+  structured concurrency
16+- React integration
17+
18+```tsx
19+import { createApi, createSchema, createStore, mdw, timer } from "starfx";
20+import { Provider, useCache } from "starfx/react";
21+
22+const [schema, initialState] = createSchema();
23+const store = createStore({ initialState });
24+
25+const api = createApi();
26+// mdw = middleware
27+api.use(mdw.api({ schema }));
28+api.use(api.routes());
29+api.use(mdw.fetch({ baseUrl: "https://api.github.com" }));
30+
31+const fetchRepo = api.get(
32+  "/repos/neurosnap/starfx",
33+  { supervisor: timer() },
34+  api.cache(),
35+);
36+
37+store.run(api.bootup);
38+
39+function App() {
40+  return (
41+    <Provider schema={schema} store={store}>
42+      <Example />
43+    </Provider>
44+  );
45+}
46+
47+function Example() {
48+  const { isInitialLoading, isError, message, data } = useCache(fetchRepo());
49+
50+  if (isInitialLoading) return "Loading ...";
51+
52+  if (isError) return `An error has occurred: ${message}`;
53+
54+  return (
55+    <div>
56+      <h1>{data.name}</h1>
57+      <p>{data.description}</p>
58+      <strong>👀 {data.subscribers_count}</strong>{" "}
59+      <strong>✨ {data.stargazers_count}</strong>{" "}
60+      <strong>🍴 {data.forks_count}</strong>
61+    </div>
62+  );
63+}
64+```