@legendapp/state 2.2.0-next.75 → 2.2.0-next.76
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/helpers/time.d.ts +2 -2
- package/index.js +7 -5
- package/index.js.map +1 -1
- package/index.mjs +7 -5
- package/index.mjs.map +1 -1
- package/package.json +11 -1
- package/persist.js +82 -87
- package/persist.js.map +1 -1
- package/persist.mjs +82 -87
- package/persist.mjs.map +1 -1
- package/src/batching.ts +2 -0
- package/src/computed.ts +4 -2
- package/src/globals.ts +1 -1
- package/src/helpers.ts +1 -1
- package/src/history/undoRedo.ts +111 -0
- package/src/observableInterfaces.ts +6 -5
- package/src/observe.ts +1 -1
- package/src/sync/activateSyncedNode.ts +2 -20
- package/src/sync/syncObservable.ts +88 -73
- package/src/sync-plugins/crud.ts +109 -98
- package/src/sync-plugins/fetch.ts +56 -26
- package/src/sync-plugins/keel.ts +447 -0
- package/src/sync-plugins/supabase.ts +225 -0
- package/src/syncTypes.ts +10 -4
- package/sync-plugins/crud.d.ts +27 -26
- package/sync-plugins/crud.js +50 -42
- package/sync-plugins/crud.js.map +1 -1
- package/sync-plugins/crud.mjs +50 -42
- package/sync-plugins/crud.mjs.map +1 -1
- package/sync-plugins/fetch.d.ts +8 -7
- package/sync-plugins/fetch.js +33 -11
- package/sync-plugins/fetch.js.map +1 -1
- package/sync-plugins/fetch.mjs +34 -12
- package/sync-plugins/fetch.mjs.map +1 -1
- package/sync-plugins/keel.d.ts +91 -0
- package/sync-plugins/keel.js +278 -0
- package/sync-plugins/keel.js.map +1 -0
- package/sync-plugins/keel.mjs +274 -0
- package/sync-plugins/keel.mjs.map +1 -0
- package/sync-plugins/supabase.d.ts +32 -0
- package/sync-plugins/supabase.js +134 -0
- package/sync-plugins/supabase.js.map +1 -0
- package/sync-plugins/supabase.mjs +131 -0
- package/sync-plugins/supabase.mjs.map +1 -0
- package/sync.js +82 -87
- package/sync.js.map +1 -1
- package/sync.mjs +83 -88
- package/sync.mjs.map +1 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var state = require('@legendapp/state');
|
|
4
|
+
var crud = require('@legendapp/state/sync-plugins/crud');
|
|
5
|
+
|
|
6
|
+
let channelNum = 1;
|
|
7
|
+
const supabaseConfig = {};
|
|
8
|
+
const isEnabled$ = state.observable(true);
|
|
9
|
+
function configureSyncedSupabase(config) {
|
|
10
|
+
const { enabled, ...rest } = config;
|
|
11
|
+
if (enabled !== undefined) {
|
|
12
|
+
isEnabled$.set(enabled);
|
|
13
|
+
}
|
|
14
|
+
Object.assign(supabaseConfig, rest);
|
|
15
|
+
}
|
|
16
|
+
function syncedSupabase(props) {
|
|
17
|
+
state.mergeIntoObservable(props, supabaseConfig);
|
|
18
|
+
const { supabase: client, collection, filter, actions, fieldUpdatedAt, realtime, changesSince, waitFor, waitForSet, ...rest } = props;
|
|
19
|
+
const list = !actions || actions.includes('read')
|
|
20
|
+
? async (params) => {
|
|
21
|
+
const { lastSync } = params;
|
|
22
|
+
let select = client.from(collection).select();
|
|
23
|
+
if (changesSince === 'last-sync') {
|
|
24
|
+
select = select.neq('deleted', true);
|
|
25
|
+
if (lastSync) {
|
|
26
|
+
const date = new Date(lastSync).toISOString();
|
|
27
|
+
select = select.or(`created_at.gt.${date}${fieldUpdatedAt ? `,${fieldUpdatedAt}.gt.${date}` : ''}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (filter) {
|
|
31
|
+
select = filter(select, params);
|
|
32
|
+
}
|
|
33
|
+
const { data, error } = await select;
|
|
34
|
+
if (error) {
|
|
35
|
+
throw new Error(error === null || error === void 0 ? void 0 : error.message);
|
|
36
|
+
}
|
|
37
|
+
return (data || []);
|
|
38
|
+
}
|
|
39
|
+
: undefined;
|
|
40
|
+
const upsert = async (input) => {
|
|
41
|
+
const res = await client.from(collection).upsert(input).select();
|
|
42
|
+
const { data, error } = res;
|
|
43
|
+
if (data) {
|
|
44
|
+
const created = data[0];
|
|
45
|
+
return created;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
throw new Error(error === null || error === void 0 ? void 0 : error.message);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const create = !actions || actions.includes('create') ? upsert : undefined;
|
|
52
|
+
const update = !actions || actions.includes('update') ? upsert : undefined;
|
|
53
|
+
const deleteFn = !actions || actions.includes('delete')
|
|
54
|
+
? async (input) => {
|
|
55
|
+
const id = input.id;
|
|
56
|
+
const from = client.from(collection);
|
|
57
|
+
const res = await (changesSince === 'last-sync' ? from.update({ deleted: true }) : from.delete())
|
|
58
|
+
.eq('id', id)
|
|
59
|
+
.select();
|
|
60
|
+
const { data, error } = res;
|
|
61
|
+
if (data) {
|
|
62
|
+
const created = data[0];
|
|
63
|
+
return created;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw new Error(error === null || error === void 0 ? void 0 : error.message);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
: undefined;
|
|
70
|
+
const subscribe = realtime
|
|
71
|
+
? ({ node, update }) => {
|
|
72
|
+
const { filter, schema } = realtime;
|
|
73
|
+
const channel = client
|
|
74
|
+
.channel(`LS_${node.key || ''}${channelNum++}`)
|
|
75
|
+
.on('postgres_changes', {
|
|
76
|
+
event: '*',
|
|
77
|
+
table: collection,
|
|
78
|
+
schema: schema || 'public',
|
|
79
|
+
filter: filter || undefined,
|
|
80
|
+
}, (payload) => {
|
|
81
|
+
var _a;
|
|
82
|
+
const { eventType, new: value, old } = payload;
|
|
83
|
+
if (eventType === 'INSERT' || eventType === 'UPDATE') {
|
|
84
|
+
const cur = (_a = state.getNodeValue(node)) === null || _a === void 0 ? void 0 : _a[value.id];
|
|
85
|
+
const curDateStr = cur && (cur.updated_at || cur.created_at);
|
|
86
|
+
const valueDateStr = value.updated_at || value.created_at;
|
|
87
|
+
const valueDate = +new Date(valueDateStr);
|
|
88
|
+
// Check if new or newer than last seen locally
|
|
89
|
+
if (valueDateStr && (!curDateStr || valueDate > +new Date(curDateStr))) {
|
|
90
|
+
// Update local with the new value
|
|
91
|
+
update({
|
|
92
|
+
value: { [value.id]: value },
|
|
93
|
+
lastSync: valueDate,
|
|
94
|
+
mode: 'merge',
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else if (eventType === 'DELETE') {
|
|
99
|
+
const { id } = old;
|
|
100
|
+
update({
|
|
101
|
+
value: { [id]: state.symbolDelete },
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
.subscribe();
|
|
106
|
+
return channel.unsubscribe;
|
|
107
|
+
}
|
|
108
|
+
: undefined;
|
|
109
|
+
return crud.syncedCrud({
|
|
110
|
+
...rest,
|
|
111
|
+
list,
|
|
112
|
+
create,
|
|
113
|
+
update,
|
|
114
|
+
delete: deleteFn,
|
|
115
|
+
onSaved: (saved) => {
|
|
116
|
+
// Update the local timestamps with server response
|
|
117
|
+
return {
|
|
118
|
+
id: saved.id,
|
|
119
|
+
created_at: saved.created_at,
|
|
120
|
+
updated_at: saved.updated_at,
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
subscribe,
|
|
124
|
+
fieldCreatedAt: 'created_at',
|
|
125
|
+
fieldUpdatedAt,
|
|
126
|
+
updatePartial: true,
|
|
127
|
+
waitFor: () => isEnabled$.get() && (waitFor ? state.computeSelector(waitFor) : true),
|
|
128
|
+
waitForSet: () => isEnabled$.get() && (waitForSet ? state.computeSelector(waitForSet) : true),
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
exports.configureSyncedSupabase = configureSyncedSupabase;
|
|
133
|
+
exports.syncedSupabase = syncedSupabase;
|
|
134
|
+
//# sourceMappingURL=supabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supabase.js","sources":["../src/sync-plugins/supabase.ts"],"sourcesContent":[null],"names":["observable","mergeIntoObservable","getNodeValue","sym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,qBAAA,CAAC,CAAC;iBACN;AACL,aAAC,CACJ;AACA,iBAAA,SAAS,EAAE,CAAC;YAEjB,OAAO,OAAO,CAAC,WAAW,CAAC;SAC9B;UACD,SAAS,CAAC;AAEhB,IAAA,OAAOC,eAAU,CAAiE;AAC9E,QAAA,GAAG,IAAI;QACP,IAAI;QACJ,MAAM;QACN,MAAM;AACN,QAAA,MAAM,EAAE,QAAQ;AAChB,QAAA,OAAO,EAAE,CAAC,KAAK,KAAI;;YAEf,OAAO;gBACH,EAAE,EAAE,KAAK,CAAC,EAAE;gBACZ,UAAU,EAAE,KAAK,CAAC,UAAU;gBAC5B,UAAU,EAAE,KAAK,CAAC,UAAU;aAC/B,CAAC;SACL;QACD,SAAS;AACT,QAAA,cAAc,EAAE,YAAY;QAC5B,cAAc;AACd,QAAA,aAAa,EAAE,IAAI;QACnB,OAAO,EAAE,MAAM,UAAU,CAAC,GAAG,EAAE,KAAK,OAAO,GAAGC,qBAAe,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;QAC9E,UAAU,EAAE,MAAM,UAAU,CAAC,GAAG,EAAE,KAAK,UAAU,GAAGA,qBAAe,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;AAC1F,KAAA,CAAC,CAAC;AACP;;;;;"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { observable, mergeIntoObservable, computeSelector, getNodeValue, symbolDelete } from '@legendapp/state';
|
|
2
|
+
import { syncedCrud } from '@legendapp/state/sync-plugins/crud';
|
|
3
|
+
|
|
4
|
+
let channelNum = 1;
|
|
5
|
+
const supabaseConfig = {};
|
|
6
|
+
const isEnabled$ = observable(true);
|
|
7
|
+
function configureSyncedSupabase(config) {
|
|
8
|
+
const { enabled, ...rest } = config;
|
|
9
|
+
if (enabled !== undefined) {
|
|
10
|
+
isEnabled$.set(enabled);
|
|
11
|
+
}
|
|
12
|
+
Object.assign(supabaseConfig, rest);
|
|
13
|
+
}
|
|
14
|
+
function syncedSupabase(props) {
|
|
15
|
+
mergeIntoObservable(props, supabaseConfig);
|
|
16
|
+
const { supabase: client, collection, filter, actions, fieldUpdatedAt, realtime, changesSince, waitFor, waitForSet, ...rest } = props;
|
|
17
|
+
const list = !actions || actions.includes('read')
|
|
18
|
+
? async (params) => {
|
|
19
|
+
const { lastSync } = params;
|
|
20
|
+
let select = client.from(collection).select();
|
|
21
|
+
if (changesSince === 'last-sync') {
|
|
22
|
+
select = select.neq('deleted', true);
|
|
23
|
+
if (lastSync) {
|
|
24
|
+
const date = new Date(lastSync).toISOString();
|
|
25
|
+
select = select.or(`created_at.gt.${date}${fieldUpdatedAt ? `,${fieldUpdatedAt}.gt.${date}` : ''}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (filter) {
|
|
29
|
+
select = filter(select, params);
|
|
30
|
+
}
|
|
31
|
+
const { data, error } = await select;
|
|
32
|
+
if (error) {
|
|
33
|
+
throw new Error(error === null || error === void 0 ? void 0 : error.message);
|
|
34
|
+
}
|
|
35
|
+
return (data || []);
|
|
36
|
+
}
|
|
37
|
+
: undefined;
|
|
38
|
+
const upsert = async (input) => {
|
|
39
|
+
const res = await client.from(collection).upsert(input).select();
|
|
40
|
+
const { data, error } = res;
|
|
41
|
+
if (data) {
|
|
42
|
+
const created = data[0];
|
|
43
|
+
return created;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
throw new Error(error === null || error === void 0 ? void 0 : error.message);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const create = !actions || actions.includes('create') ? upsert : undefined;
|
|
50
|
+
const update = !actions || actions.includes('update') ? upsert : undefined;
|
|
51
|
+
const deleteFn = !actions || actions.includes('delete')
|
|
52
|
+
? async (input) => {
|
|
53
|
+
const id = input.id;
|
|
54
|
+
const from = client.from(collection);
|
|
55
|
+
const res = await (changesSince === 'last-sync' ? from.update({ deleted: true }) : from.delete())
|
|
56
|
+
.eq('id', id)
|
|
57
|
+
.select();
|
|
58
|
+
const { data, error } = res;
|
|
59
|
+
if (data) {
|
|
60
|
+
const created = data[0];
|
|
61
|
+
return created;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
throw new Error(error === null || error === void 0 ? void 0 : error.message);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
: undefined;
|
|
68
|
+
const subscribe = realtime
|
|
69
|
+
? ({ node, update }) => {
|
|
70
|
+
const { filter, schema } = realtime;
|
|
71
|
+
const channel = client
|
|
72
|
+
.channel(`LS_${node.key || ''}${channelNum++}`)
|
|
73
|
+
.on('postgres_changes', {
|
|
74
|
+
event: '*',
|
|
75
|
+
table: collection,
|
|
76
|
+
schema: schema || 'public',
|
|
77
|
+
filter: filter || undefined,
|
|
78
|
+
}, (payload) => {
|
|
79
|
+
var _a;
|
|
80
|
+
const { eventType, new: value, old } = payload;
|
|
81
|
+
if (eventType === 'INSERT' || eventType === 'UPDATE') {
|
|
82
|
+
const cur = (_a = getNodeValue(node)) === null || _a === void 0 ? void 0 : _a[value.id];
|
|
83
|
+
const curDateStr = cur && (cur.updated_at || cur.created_at);
|
|
84
|
+
const valueDateStr = value.updated_at || value.created_at;
|
|
85
|
+
const valueDate = +new Date(valueDateStr);
|
|
86
|
+
// Check if new or newer than last seen locally
|
|
87
|
+
if (valueDateStr && (!curDateStr || valueDate > +new Date(curDateStr))) {
|
|
88
|
+
// Update local with the new value
|
|
89
|
+
update({
|
|
90
|
+
value: { [value.id]: value },
|
|
91
|
+
lastSync: valueDate,
|
|
92
|
+
mode: 'merge',
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else if (eventType === 'DELETE') {
|
|
97
|
+
const { id } = old;
|
|
98
|
+
update({
|
|
99
|
+
value: { [id]: symbolDelete },
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
.subscribe();
|
|
104
|
+
return channel.unsubscribe;
|
|
105
|
+
}
|
|
106
|
+
: undefined;
|
|
107
|
+
return syncedCrud({
|
|
108
|
+
...rest,
|
|
109
|
+
list,
|
|
110
|
+
create,
|
|
111
|
+
update,
|
|
112
|
+
delete: deleteFn,
|
|
113
|
+
onSaved: (saved) => {
|
|
114
|
+
// Update the local timestamps with server response
|
|
115
|
+
return {
|
|
116
|
+
id: saved.id,
|
|
117
|
+
created_at: saved.created_at,
|
|
118
|
+
updated_at: saved.updated_at,
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
subscribe,
|
|
122
|
+
fieldCreatedAt: 'created_at',
|
|
123
|
+
fieldUpdatedAt,
|
|
124
|
+
updatePartial: true,
|
|
125
|
+
waitFor: () => isEnabled$.get() && (waitFor ? computeSelector(waitFor) : true),
|
|
126
|
+
waitForSet: () => isEnabled$.get() && (waitForSet ? computeSelector(waitForSet) : true),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export { configureSyncedSupabase, syncedSupabase };
|
|
131
|
+
//# sourceMappingURL=supabase.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supabase.mjs","sources":["../src/sync-plugins/supabase.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AA4EA,IAAI,UAAU,GAAG,CAAC,CAAC;AACnB,MAAM,cAAc,GAA+B,EAAE,CAAC;AACtD,MAAM,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;AAE9B,SAAU,uBAAuB,CAAC,MAAkC,EAAA;IACtE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;AACpC,IAAA,IAAI,OAAO,KAAK,SAAS,EAAE;AACvB,QAAA,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;KAC3B;AACD,IAAA,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC;AAEK,SAAU,cAAc,CAI5B,KAAwD,EAAA;AACtD,IAAA,mBAAmB,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IAC3C,MAA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AAE,KAAK,OAAO,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;QAC9E,UAAU,EAAE,MAAM,UAAU,CAAC,GAAG,EAAE,KAAK,UAAU,GAAG,eAAe,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;AAC1F,KAAA,CAAC,CAAC;AACP;;;;"}
|
package/sync.js
CHANGED
|
@@ -675,6 +675,77 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
675
675
|
const get = (_b = localState.pluginSync.get) === null || _b === void 0 ? void 0 : _b.bind(localState.pluginSync);
|
|
676
676
|
if (get) {
|
|
677
677
|
const runGet = () => {
|
|
678
|
+
const onChange = async ({ value, mode, lastSync }) => {
|
|
679
|
+
mode = mode || syncOptions.mode || 'set';
|
|
680
|
+
if (value !== undefined) {
|
|
681
|
+
value = transformLoadData(value, syncOptions, true);
|
|
682
|
+
if (state.isPromise(value)) {
|
|
683
|
+
value = await value;
|
|
684
|
+
}
|
|
685
|
+
const pending = localState.pendingChanges;
|
|
686
|
+
const currentValue = obs$.peek();
|
|
687
|
+
if (pending) {
|
|
688
|
+
let didChangeMetadata = false;
|
|
689
|
+
Object.keys(pending).forEach((key) => {
|
|
690
|
+
const p = key.split('/').filter((p) => p !== '');
|
|
691
|
+
const { v, t } = pending[key];
|
|
692
|
+
if (t.length === 0 || !value) {
|
|
693
|
+
if (state.isObject(value) && state.isObject(v)) {
|
|
694
|
+
Object.assign(value, v);
|
|
695
|
+
}
|
|
696
|
+
else {
|
|
697
|
+
value = v;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
else if (value[p[0]] !== undefined) {
|
|
701
|
+
const curValue = getValueAtPath(currentValue, p);
|
|
702
|
+
const newValue = getValueAtPath(value, p);
|
|
703
|
+
if (JSON.stringify(curValue) === JSON.stringify(newValue)) {
|
|
704
|
+
delete pending[key];
|
|
705
|
+
didChangeMetadata = true;
|
|
706
|
+
}
|
|
707
|
+
else {
|
|
708
|
+
value = state.setAtPath(value, p, t, v, 'merge', obs$.peek(), (path, value) => {
|
|
709
|
+
delete pending[key];
|
|
710
|
+
pending[path.join('/')] = {
|
|
711
|
+
p: null,
|
|
712
|
+
v: value,
|
|
713
|
+
t: t.slice(0, path.length),
|
|
714
|
+
};
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
});
|
|
719
|
+
if (didChangeMetadata) {
|
|
720
|
+
updateMetadata(obs$, localState, syncState, syncOptions, {
|
|
721
|
+
pending,
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
onChangeRemote(() => {
|
|
726
|
+
if (mode === 'assign' && state.isObject(value)) {
|
|
727
|
+
obs$.assign(value);
|
|
728
|
+
}
|
|
729
|
+
else if (mode === 'append' && state.isArray(value)) {
|
|
730
|
+
obs$.push(...value);
|
|
731
|
+
}
|
|
732
|
+
else if (mode === 'prepend' && state.isArray(value)) {
|
|
733
|
+
obs$.splice(0, 0, ...value);
|
|
734
|
+
}
|
|
735
|
+
else if (mode === 'merge') {
|
|
736
|
+
state.mergeIntoObservable(obs$, value);
|
|
737
|
+
}
|
|
738
|
+
else {
|
|
739
|
+
obs$.set(value);
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
if (lastSync && syncOptions.persist) {
|
|
744
|
+
updateMetadata(obs$, localState, syncState, syncOptions, {
|
|
745
|
+
lastSync,
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
};
|
|
678
749
|
get({
|
|
679
750
|
state: syncState,
|
|
680
751
|
obs: obs$,
|
|
@@ -686,82 +757,23 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
686
757
|
(_a = syncOptions.onGetError) === null || _a === void 0 ? void 0 : _a.call(syncOptions, error);
|
|
687
758
|
},
|
|
688
759
|
onGet: () => {
|
|
760
|
+
const isFirstLoad = !node.state.isLoaded.peek();
|
|
689
761
|
node.state.assign({
|
|
690
762
|
isLoaded: true,
|
|
691
763
|
error: undefined,
|
|
692
764
|
});
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
const pending = localState.pendingChanges;
|
|
702
|
-
const currentValue = obs$.peek();
|
|
703
|
-
if (pending) {
|
|
704
|
-
let didChangeMetadata = false;
|
|
705
|
-
Object.keys(pending).forEach((key) => {
|
|
706
|
-
const p = key.split('/').filter((p) => p !== '');
|
|
707
|
-
const { v, t } = pending[key];
|
|
708
|
-
if (t.length === 0 || !value) {
|
|
709
|
-
if (state.isObject(value) && state.isObject(v)) {
|
|
710
|
-
Object.assign(value, v);
|
|
711
|
-
}
|
|
712
|
-
else {
|
|
713
|
-
value = v;
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
else if (value[p[0]] !== undefined) {
|
|
717
|
-
const curValue = getValueAtPath(currentValue, p);
|
|
718
|
-
const newValue = getValueAtPath(value, p);
|
|
719
|
-
if (JSON.stringify(curValue) === JSON.stringify(newValue)) {
|
|
720
|
-
delete pending[key];
|
|
721
|
-
didChangeMetadata = true;
|
|
722
|
-
}
|
|
723
|
-
else {
|
|
724
|
-
value = state.setAtPath(value, p, t, v, 'merge', obs$.peek(), (path, value) => {
|
|
725
|
-
delete pending[key];
|
|
726
|
-
pending[path.join('/')] = {
|
|
727
|
-
p: null,
|
|
728
|
-
v: value,
|
|
729
|
-
t: t.slice(0, path.length),
|
|
730
|
-
};
|
|
731
|
-
});
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
});
|
|
735
|
-
if (didChangeMetadata) {
|
|
736
|
-
updateMetadata(obs$, localState, syncState, syncOptions, {
|
|
737
|
-
pending,
|
|
738
|
-
});
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
onChangeRemote(() => {
|
|
742
|
-
if (mode === 'assign' && state.isObject(value)) {
|
|
743
|
-
obs$.assign(value);
|
|
744
|
-
}
|
|
745
|
-
else if (mode === 'append' && state.isArray(value)) {
|
|
746
|
-
obs$.push(...value);
|
|
747
|
-
}
|
|
748
|
-
else if (mode === 'prepend' && state.isArray(value)) {
|
|
749
|
-
obs$.splice(0, 0, ...value);
|
|
750
|
-
}
|
|
751
|
-
else if (mode === 'merge') {
|
|
752
|
-
state.mergeIntoObservable(obs$, value);
|
|
753
|
-
}
|
|
754
|
-
else {
|
|
755
|
-
obs$.set(value);
|
|
756
|
-
}
|
|
757
|
-
});
|
|
758
|
-
}
|
|
759
|
-
if (lastSync && syncOptions.persist) {
|
|
760
|
-
updateMetadata(obs$, localState, syncState, syncOptions, {
|
|
761
|
-
lastSync,
|
|
765
|
+
if (isFirstLoad && syncOptions.subscribe) {
|
|
766
|
+
syncOptions.subscribe({
|
|
767
|
+
node,
|
|
768
|
+
update: (params) => {
|
|
769
|
+
params.mode || (params.mode = syncOptions.mode || 'merge');
|
|
770
|
+
onChange(params);
|
|
771
|
+
},
|
|
772
|
+
refresh: sync,
|
|
762
773
|
});
|
|
763
774
|
}
|
|
764
775
|
},
|
|
776
|
+
onChange,
|
|
765
777
|
});
|
|
766
778
|
};
|
|
767
779
|
runGet();
|
|
@@ -831,7 +843,7 @@ function enableActivateSyncedNode() {
|
|
|
831
843
|
const obs$ = getProxy(node);
|
|
832
844
|
if (node.activationState) {
|
|
833
845
|
// If it is a Synced
|
|
834
|
-
const { get, initial, set
|
|
846
|
+
const { get, initial, set } = node.activationState;
|
|
835
847
|
let onChange = undefined;
|
|
836
848
|
const pluginRemote = {};
|
|
837
849
|
let promiseReturn = undefined;
|
|
@@ -906,23 +918,6 @@ function enableActivateSyncedNode() {
|
|
|
906
918
|
setNodeValue(node, promiseReturn ? undefined : newValue);
|
|
907
919
|
// @ts-expect-error TODO fix these types
|
|
908
920
|
syncState = syncObservable(obs$, { ...node.activationState, ...pluginRemote });
|
|
909
|
-
if (subscribe) {
|
|
910
|
-
state.when(promiseReturn || true, () => {
|
|
911
|
-
subscribe({
|
|
912
|
-
node,
|
|
913
|
-
update: (params) => {
|
|
914
|
-
if (!onChange) {
|
|
915
|
-
// TODO: Make this message better
|
|
916
|
-
console.log('[legend-state] Cannot update immediately before the first return');
|
|
917
|
-
}
|
|
918
|
-
else {
|
|
919
|
-
onChange(params);
|
|
920
|
-
}
|
|
921
|
-
},
|
|
922
|
-
refresh,
|
|
923
|
-
});
|
|
924
|
-
});
|
|
925
|
-
}
|
|
926
921
|
return { update: onChange, value: newValue };
|
|
927
922
|
}
|
|
928
923
|
else {
|