@rivetkit/framework-base 2.0.5 → 2.0.7-rc.1
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/mod.cjs +1 -1
- package/dist/mod.d.ts +0 -1
- package/dist/mod.js +15 -16
- package/package.json +2 -2
package/dist/mod.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=new WeakMap,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=new WeakMap,v=new WeakMap,g={current:[]};let b=!1;const S=new Set,k=new Map;function C(i){const n=Array.from(i).sort((t,e)=>t instanceof f&&t.options.deps.includes(e)?1:e instanceof f&&e.options.deps.includes(t)?-1:0);for(const t of n){if(g.current.includes(t))continue;g.current.push(t),t.recompute();const e=v.get(t);if(e)for(const s of e){const o=p.get(s);o&&C(o)}}}function O(i){i.listeners.forEach(n=>n({prevVal:i.prevState,currentVal:i.state}))}function F(i){i.listeners.forEach(n=>n({prevVal:i.prevState,currentVal:i.state}))}function R(i){if(S.add(i),!b)try{for(b=!0;S.size>0;){const n=Array.from(S);S.clear();for(const t of n){const e=k.get(t)??t.prevState;t.prevState=e,O(t)}for(const t of n){const e=p.get(t);e&&(g.current.push(t),C(e))}for(const t of n){const e=p.get(t);if(e)for(const s of e)F(s)}}}finally{b=!1,g.current=[],k.clear()}}function G(i){return typeof i=="function"}class m{constructor(n,t){this.listeners=new Set,this.subscribe=e=>{var s,o;this.listeners.add(e);const h=(o=(s=this.options)==null?void 0:s.onSubscribe)==null?void 0:o.call(s,e,this);return()=>{this.listeners.delete(e),h==null||h()}},this.prevState=n,this.state=n,this.options=t}setState(n){var t,e,s;this.prevState=this.state,(t=this.options)!=null&&t.updateFn?this.state=this.options.updateFn(this.prevState)(n):G(n)?this.state=n(this.prevState):this.state=n,(s=(e=this.options)==null?void 0:e.onUpdate)==null||s.call(e),R(this)}}class f{constructor(n){this.listeners=new Set,this._subscriptions=[],this.lastSeenDepValues=[],this.getDepVals=()=>{const t=[],e=[];for(const s of this.options.deps)t.push(s.prevState),e.push(s.state);return this.lastSeenDepValues=e,{prevDepVals:t,currDepVals:e,prevVal:this.prevState??void 0}},this.recompute=()=>{var t,e;this.prevState=this.state;const{prevDepVals:s,currDepVals:o,prevVal:h}=this.getDepVals();this.state=this.options.fn({prevDepVals:s,currDepVals:o,prevVal:h}),(e=(t=this.options).onUpdate)==null||e.call(t)},this.checkIfRecalculationNeededDeeply=()=>{for(const o of this.options.deps)o instanceof f&&o.checkIfRecalculationNeededDeeply();let t=!1;const e=this.lastSeenDepValues,{currDepVals:s}=this.getDepVals();for(let o=0;o<s.length;o++)if(s[o]!==e[o]){t=!0;break}t&&this.recompute()},this.mount=()=>(this.registerOnGraph(),this.checkIfRecalculationNeededDeeply(),()=>{this.unregisterFromGraph();for(const t of this._subscriptions)t()}),this.subscribe=t=>{var e,s;this.listeners.add(t);const o=(s=(e=this.options).onSubscribe)==null?void 0:s.call(e,t,this);return()=>{this.listeners.delete(t),o==null||o()}},this.options=n,this.state=n.fn({prevDepVals:void 0,prevVal:void 0,currDepVals:this.getDepVals().currDepVals})}registerOnGraph(n=this.options.deps){for(const t of n)if(t instanceof f)t.registerOnGraph(),this.registerOnGraph(t.options.deps);else if(t instanceof m){let e=p.get(t);e||(e=new Set,p.set(t,e)),e.add(this);let s=v.get(this);s||(s=new Set,v.set(this,s)),s.add(t)}}unregisterFromGraph(n=this.options.deps){for(const t of n)if(t instanceof f)this.unregisterFromGraph(t.options.deps);else if(t instanceof m){const e=p.get(t);e&&e.delete(this);const s=v.get(this);s&&s.delete(t)}}}class I{constructor(n){const{eager:t,fn:e,...s}=n;this._derived=new f({...s,fn:()=>{},onUpdate(){e()}}),t&&e()}mount(){return this._derived.mount()}}function N(i,n={}){const t=new m({actors:{}}),e=n.hashFunction||T,s=new Map;function o(h){const r=e(h),_=s.get(r);if(_)return{..._,state:_.state};const d=new f({fn:({currDepVals:[a]})=>a.actors[r],deps:[t]});function V(){async function a(){const c=t.state.actors[r];try{const u=i.getOrCreate(c.opts.name,c.opts.key,{params:c.opts.params,createInRegion:c.opts.createInRegion,createWithInput:c.opts.createWithInput}),l=u.connect();await u.resolve(),t.setState(D=>({...D,actors:{...D.actors,[r]:{...D.actors[r],isConnected:!0,isConnecting:!1,handle:u,connection:l,isError:!1,error:null}}}))}catch(u){t.setState(l=>({...l,actors:{...l.actors,[r]:{...l.actors[r],isError:!0,isConnecting:!1,error:u}}}))}}t.setState(c=>(c.actors[r].isConnecting=!0,c.actors[r].isError=!1,c.actors[r].error=null,a(),c))}const E=new I({fn:()=>{const a=t.state.actors[r];JSON.stringify(t.prevState.actors[r].opts)===JSON.stringify(t.state.actors[r].opts)&&!a.isConnected&&!a.isConnecting&&!a.isError&&a.opts.enabled&&V()},deps:[d]});t.setState(a=>a.actors[r]?a:{...a,actors:{...a.actors,[r]:{hash:r,isConnected:!1,isConnecting:!1,connection:null,handle:null,isError:!1,error:null,opts:h}}});function y(a){t.setState(c=>{const u=c.actors[r];if(!u)throw new Error(`Actor with key "${r}" does not exist.`);let l;return typeof a=="function"?l=a(u):l=a,{...c,actors:{...c.actors,[r]:l}}})}const w=()=>{const a=d.mount(),c=E.mount();return()=>{a(),c()}};return s.set(r,{state:d,key:r,mount:w,setState:y,create:V}),{mount:w,setState:y,state:d,create:V,key:r}}return{getOrCreateActor:o,store:t}}function T({name:i,key:n,params:t}){return JSON.stringify({name:i,key:n,params:t})}exports.createRivetKit=N;
|
package/dist/mod.d.ts
CHANGED
|
@@ -111,7 +111,6 @@ export declare function createRivetKit<Registry extends AnyActorRegistry, Actors
|
|
|
111
111
|
mount: () => void;
|
|
112
112
|
setState: (set: Updater<ActorStateReference<Actors>>) => void;
|
|
113
113
|
create: () => void;
|
|
114
|
-
addEventListener?: (event: string, handler: (...args: any[]) => void) => void;
|
|
115
114
|
};
|
|
116
115
|
store: Store<InternalRivetKitStore<Registry, Actors>, (cb: InternalRivetKitStore<Registry, Actors>) => InternalRivetKitStore<Registry, Actors>>;
|
|
117
116
|
};
|
package/dist/mod.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
const p = /* @__PURE__ */ new WeakMap(),
|
|
1
|
+
const p = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakMap(), g = {
|
|
2
2
|
current: []
|
|
3
3
|
};
|
|
4
4
|
let b = !1;
|
|
5
|
-
const
|
|
5
|
+
const S = /* @__PURE__ */ new Set(), k = /* @__PURE__ */ new Map();
|
|
6
6
|
function C(i) {
|
|
7
7
|
const n = Array.from(i).sort((t, e) => t instanceof f && t.options.deps.includes(e) ? 1 : e instanceof f && e.options.deps.includes(t) ? -1 : 0);
|
|
8
8
|
for (const t of n) {
|
|
9
9
|
if (g.current.includes(t))
|
|
10
10
|
continue;
|
|
11
11
|
g.current.push(t), t.recompute();
|
|
12
|
-
const e =
|
|
12
|
+
const e = v.get(t);
|
|
13
13
|
if (e)
|
|
14
14
|
for (const s of e) {
|
|
15
15
|
const o = p.get(s);
|
|
@@ -34,11 +34,11 @@ function O(i) {
|
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
36
|
function G(i) {
|
|
37
|
-
if (
|
|
37
|
+
if (S.add(i), !b)
|
|
38
38
|
try {
|
|
39
|
-
for (b = !0;
|
|
40
|
-
const n = Array.from(
|
|
41
|
-
|
|
39
|
+
for (b = !0; S.size > 0; ) {
|
|
40
|
+
const n = Array.from(S);
|
|
41
|
+
S.clear();
|
|
42
42
|
for (const t of n) {
|
|
43
43
|
const e = k.get(t) ?? t.prevState;
|
|
44
44
|
t.prevState = e, F(t);
|
|
@@ -132,8 +132,8 @@ class f {
|
|
|
132
132
|
else if (t instanceof m) {
|
|
133
133
|
let e = p.get(t);
|
|
134
134
|
e || (e = /* @__PURE__ */ new Set(), p.set(t, e)), e.add(this);
|
|
135
|
-
let s =
|
|
136
|
-
s || (s = /* @__PURE__ */ new Set(),
|
|
135
|
+
let s = v.get(this);
|
|
136
|
+
s || (s = /* @__PURE__ */ new Set(), v.set(this, s)), s.add(t);
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
unregisterFromGraph(n = this.options.deps) {
|
|
@@ -143,7 +143,7 @@ class f {
|
|
|
143
143
|
else if (t instanceof m) {
|
|
144
144
|
const e = p.get(t);
|
|
145
145
|
e && e.delete(this);
|
|
146
|
-
const s =
|
|
146
|
+
const s = v.get(this);
|
|
147
147
|
s && s.delete(t);
|
|
148
148
|
}
|
|
149
149
|
}
|
|
@@ -164,10 +164,10 @@ class R {
|
|
|
164
164
|
return this._derived.mount();
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
-
function
|
|
167
|
+
function A(i, n = {}) {
|
|
168
168
|
const t = new m({
|
|
169
169
|
actors: {}
|
|
170
|
-
}), e = n.hashFunction ||
|
|
170
|
+
}), e = n.hashFunction || N, s = /* @__PURE__ */ new Map();
|
|
171
171
|
function o(h) {
|
|
172
172
|
const r = e(h), _ = s.get(r);
|
|
173
173
|
if (_)
|
|
@@ -275,8 +275,7 @@ function N(i, n = {}) {
|
|
|
275
275
|
key: r,
|
|
276
276
|
mount: y,
|
|
277
277
|
setState: w,
|
|
278
|
-
create: V
|
|
279
|
-
addEventListener
|
|
278
|
+
create: V
|
|
280
279
|
}), {
|
|
281
280
|
mount: y,
|
|
282
281
|
setState: w,
|
|
@@ -290,9 +289,9 @@ function N(i, n = {}) {
|
|
|
290
289
|
store: t
|
|
291
290
|
};
|
|
292
291
|
}
|
|
293
|
-
function
|
|
292
|
+
function N({ name: i, key: n, params: t }) {
|
|
294
293
|
return JSON.stringify({ name: i, key: n, params: t });
|
|
295
294
|
}
|
|
296
295
|
export {
|
|
297
|
-
|
|
296
|
+
A as createRivetKit
|
|
298
297
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rivetkit/framework-base",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7-rc.1",
|
|
4
4
|
"description": "Base framework utilities for RivetKit client integrations",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"stableVersion": "0.8.0",
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@tanstack/store": "^0.7.1",
|
|
40
|
-
"rivetkit": "2.0.
|
|
40
|
+
"rivetkit": "2.0.7-rc.1"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"dev": "vite build --watch",
|