Skip to content

Commit 352182e

Browse files
committed
removing vdombindings and atom state sync (simplify)
1 parent 7fa0786 commit 352182e

7 files changed

Lines changed: 0 additions & 138 deletions

File tree

tsunami/engine/clientimpl.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,6 @@ func (c *ClientImpl) SendAsyncInitiation() error {
218218
}
219219
}
220220

221-
func (c *ClientImpl) SetAtomVals(m map[string]any) {
222-
for k, v := range m {
223-
c.Root.SetAtomVal(k, v, true)
224-
}
225-
}
226-
227221
func (c *ClientImpl) SetAtomVal(name string, val any) {
228222
c.Root.SetAtomVal(name, val, true)
229223
}
@@ -283,7 +277,6 @@ func (c *ClientImpl) fullRender() (*rpctypes.VDomBackendUpdate, error) {
283277
{UpdateType: "root", VDom: renderedVDom},
284278
},
285279
RefOperations: c.Root.GetRefOperations(),
286-
StateSync: c.Root.GetStateSync(true),
287280
}, nil
288281
}
289282

@@ -304,7 +297,6 @@ func (c *ClientImpl) incrementalRender() (*rpctypes.VDomBackendUpdate, error) {
304297
{UpdateType: "root", VDom: renderedVDom},
305298
},
306299
RefOperations: c.Root.GetRefOperations(),
307-
StateSync: c.Root.GetStateSync(false),
308300
}, nil
309301
}
310302

tsunami/engine/rootelem.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ type RenderOpts struct {
3838

3939
type atomImpl struct {
4040
Val any
41-
Dirty bool
4241
UsedBy map[string]bool // component waveid -> true
4342
}
4443

@@ -165,20 +164,6 @@ func (r *RootElem) GetAtomVal(name string) any {
165164
return atom.Val
166165
}
167166

168-
func (r *RootElem) GetStateSync(full bool) []rpctypes.VDomStateSync {
169-
r.atomLock.Lock()
170-
defer r.atomLock.Unlock()
171-
172-
stateSync := make([]rpctypes.VDomStateSync, 0)
173-
for atomName, atom := range r.Atoms {
174-
if atom.Dirty || full {
175-
stateSync = append(stateSync, rpctypes.VDomStateSync{Atom: atomName, Value: atom.Val})
176-
atom.Dirty = false
177-
}
178-
}
179-
return stateSync
180-
}
181-
182167
func (r *RootElem) SetAtomVal(name string, val any, markDirty bool) {
183168
r.atomLock.Lock()
184169
defer r.atomLock.Unlock()
@@ -193,7 +178,6 @@ func (r *RootElem) SetAtomVal(name string, val any, markDirty bool) {
193178
return
194179
}
195180
atom.Val = val
196-
atom.Dirty = true
197181
}
198182

199183
func (r *RootElem) RemoveAtom(name string) {

tsunami/engine/serverhandlers.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@ func (h *httpHandlers) processFrontendUpdate(feUpdate *rpctypes.VDomFrontendUpda
128128

129129
h.Client.Root.RenderTs = feUpdate.Ts
130130

131-
// set atoms
132-
for _, ss := range feUpdate.StateSync {
133-
h.Client.Root.SetAtomVal(ss.Atom, ss.Value, false)
134-
}
135131
// run events
136132
for _, event := range feUpdate.Events {
137133
if event.GlobalEventType != "" {

tsunami/frontend/src/model/tsunami-model.tsx

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ import { applyCanvasOp, restoreVDomElems } from "./model-utils";
1212

1313
const dlog = debug("wave:vdom");
1414

15-
type AtomContainer = {
16-
val: any;
17-
beVal: any;
18-
usedBy: Set<string>;
19-
};
20-
2115
type RefContainer = {
2216
refFn: (elem: HTMLElement) => void;
2317
vdomRef: VDomRef;
@@ -86,13 +80,11 @@ export class TsunamiModel {
8680
serverId: string;
8781
viewRef: React.RefObject<HTMLDivElement> = { current: null };
8882
vdomRoot: jotai.PrimitiveAtom<VDomElem> = jotai.atom();
89-
atoms: Map<string, AtomContainer> = new Map(); // key is atomname
9083
refs: Map<string, RefContainer> = new Map(); // key is refid
9184
batchedEvents: VDomEvent[] = [];
9285
messages: VDomMessage[] = [];
9386
needsResync: boolean = true;
9487
vdomNodeVersion: WeakMap<VDomElem, jotai.PrimitiveAtom<number>> = new WeakMap();
95-
compoundAtoms: Map<string, jotai.PrimitiveAtom<{ [key: string]: any }>> = new Map();
9688
rootRefId: string = crypto.randomUUID();
9789
backendOpts: VDomBackendOpts;
9890
shouldDispose: boolean;
@@ -155,13 +147,11 @@ export class TsunamiModel {
155147
this.serverEventSource = null;
156148
}
157149
getDefaultStore().set(this.vdomRoot, null);
158-
this.atoms.clear();
159150
this.refs.clear();
160151
this.batchedEvents = [];
161152
this.messages = [];
162153
this.needsResync = true;
163154
this.vdomNodeVersion = new WeakMap();
164-
this.compoundAtoms.clear();
165155
this.rootRefId = crypto.randomUUID();
166156
this.backendOpts = {};
167157
this.shouldDispose = false;
@@ -326,18 +316,6 @@ export class TsunamiModel {
326316
}
327317
}
328318

329-
getAtomContainer(atomName: string): AtomContainer {
330-
let container = this.atoms.get(atomName);
331-
if (container == null) {
332-
container = {
333-
val: null,
334-
beVal: null,
335-
usedBy: new Set(),
336-
};
337-
this.atoms.set(atomName, container);
338-
}
339-
return container;
340-
}
341319

342320
getOrCreateRefContainer(vdomRef: VDomRef): RefContainer {
343321
let container = this.refs.get(vdomRef.refid);
@@ -360,19 +338,6 @@ export class TsunamiModel {
360338
return container;
361339
}
362340

363-
tagUseAtoms(waveId: string, atomNames: Set<string>) {
364-
for (let atomName of atomNames) {
365-
let container = this.getAtomContainer(atomName);
366-
container.usedBy.add(waveId);
367-
}
368-
}
369-
370-
tagUnuseAtoms(waveId: string, atomNames: Set<string>) {
371-
for (let atomName of atomNames) {
372-
let container = this.getAtomContainer(atomName);
373-
container.usedBy.delete(waveId);
374-
}
375-
}
376341

377342
getVDomNodeVersionAtom(vdom: VDomElem) {
378343
let atom = this.vdomNodeVersion.get(vdom);
@@ -469,53 +434,6 @@ export class TsunamiModel {
469434
}
470435
}
471436

472-
setAtomValue(atomName: string, value: any, fromBe: boolean, idMap: Map<string, VDomElem>) {
473-
dlog("setAtomValue", atomName, value, fromBe);
474-
let container = this.getAtomContainer(atomName);
475-
if (container.val === value) {
476-
return;
477-
}
478-
container.val = value;
479-
if (fromBe) {
480-
container.beVal = value;
481-
}
482-
for (let id of container.usedBy) {
483-
this.incVDomNodeVersion(idMap.get(id));
484-
}
485-
}
486-
487-
handleStateSync(update: VDomBackendUpdate, idMap: Map<string, VDomElem>) {
488-
if (update.fullupdate) {
489-
if (update.statesync == null) {
490-
this.atoms.clear();
491-
return;
492-
}
493-
494-
const sentAtoms = new Set<string>();
495-
for (let sync of update.statesync) {
496-
sentAtoms.add(sync.atom);
497-
this.setAtomValue(sync.atom, sync.value, true, idMap);
498-
}
499-
500-
const atomsToRemove: string[] = [];
501-
for (let atomName of this.atoms.keys()) {
502-
if (!sentAtoms.has(atomName)) {
503-
atomsToRemove.push(atomName);
504-
}
505-
}
506-
507-
for (let atomName of atomsToRemove) {
508-
this.atoms.delete(atomName);
509-
}
510-
} else {
511-
if (update.statesync == null) {
512-
return;
513-
}
514-
for (let sync of update.statesync) {
515-
this.setAtomValue(sync.atom, sync.value, true, idMap);
516-
}
517-
}
518-
}
519437

520438
getRefElem(refId: string): HTMLElement {
521439
if (refId == this.rootRefId) {
@@ -607,7 +525,6 @@ export class TsunamiModel {
607525
}
608526
makeVDomIdMap(vdomRoot, idMap);
609527
this.handleRenderUpdates(update, idMap);
610-
this.handleStateSync(update, idMap);
611528
this.handleRefOperations(update, idMap);
612529
if (update.messages) {
613530
for (let message of update.messages) {

tsunami/frontend/src/types/vdom.d.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,10 @@ type VDomBackendUpdate = {
2525
fullupdate?: boolean;
2626
renderupdates?: VDomRenderUpdate[];
2727
transferelems?: VDomTransferElem[];
28-
statesync?: VDomStateSync[];
2928
refoperations?: VDomRefOperation[];
3029
messages?: VDomMessage[];
3130
};
3231

33-
// vdom.VDomBinding
34-
type VDomBinding = {
35-
type: "binding";
36-
bind: string;
37-
};
38-
3932
// vdom.VDomCreateContext
4033
type VDomCreateContext = {
4134
type: "createcontext";
@@ -78,7 +71,6 @@ type VDomFrontendUpdate = {
7871
resync?: boolean;
7972
rendercontext: VDomRenderContext;
8073
events?: VDomEvent[];
81-
statesync?: VDomStateSync[];
8274
refupdates?: VDomRefUpdate[];
8375
messages?: VDomMessage[];
8476
};
@@ -152,12 +144,6 @@ type VDomRenderUpdate = {
152144
index?: number;
153145
};
154146

155-
// vdom.VDomStateSync
156-
type VDomStateSync = {
157-
atom: string;
158-
value: any;
159-
};
160-
161147
// vdom.VDomTarget
162148
type VDomTarget = {
163149
newblock?: boolean;

tsunami/rpctypes/protocoltypes.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ type VDomFrontendUpdate struct {
4040
Resync bool `json:"resync,omitempty"` // resync (send all backend data). useful when the FE reloads
4141
RenderContext VDomRenderContext `json:"rendercontext,omitempty"`
4242
Events []vdom.VDomEvent `json:"events,omitempty"`
43-
StateSync []VDomStateSync `json:"statesync,omitempty"`
4443
RefUpdates []VDomRefUpdate `json:"refupdates,omitempty"`
4544
Messages []VDomMessage `json:"messages,omitempty"`
4645
}
@@ -54,7 +53,6 @@ type VDomBackendUpdate struct {
5453
FullUpdate bool `json:"fullupdate,omitempty"`
5554
RenderUpdates []VDomRenderUpdate `json:"renderupdates,omitempty"`
5655
TransferElems []VDomTransferElem `json:"transferelems,omitempty"`
57-
StateSync []VDomStateSync `json:"statesync,omitempty"`
5856
RefOperations []vdom.VDomRefOperation `json:"refoperations,omitempty"`
5957
Messages []VDomMessage `json:"messages,omitempty"`
6058
}
@@ -157,10 +155,6 @@ type VDomRenderContext struct {
157155
Background bool `json:"background,omitempty"`
158156
}
159157

160-
type VDomStateSync struct {
161-
Atom string `json:"atom"`
162-
Value any `json:"value"`
163-
}
164158

165159
type VDomRefUpdate struct {
166160
RefId string `json:"refid"`

tsunami/vdom/vdom_types.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const FragmentTag = "#fragment"
1111
const KeyPropKey = "key"
1212

1313
const ObjectType_Ref = "ref"
14-
const ObjectType_Binding = "binding"
1514
const ObjectType_Func = "func"
1615

1716
// vdom element
@@ -23,12 +22,6 @@ type VDomElem struct {
2322
Text string `json:"text,omitempty"`
2423
}
2524

26-
// used in props
27-
type VDomBinding struct {
28-
Type string `json:"type" tstype:"\"binding\""`
29-
Bind string `json:"bind"`
30-
}
31-
3225
// used in props
3326
type VDomFunc struct {
3427
Fn any `json:"-"` // server side function (called with reflection)

0 commit comments

Comments
 (0)