@goodandready/dsh-model-sync 0.2.4 → 0.2.5
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/lib/index.js +18 -8
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -34,10 +34,11 @@ export function apply(ctx, config) {
|
|
|
34
34
|
return saveConfigImpl(patch)
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const scope =
|
|
37
|
+
let settingsScope
|
|
38
|
+
const bindSettings = (settings, ownerCtx) => {
|
|
39
|
+
if (settingsScope || !settings?.register) return false
|
|
40
|
+
const scope = settings.register(NS, Config, { base: baseConfig })
|
|
41
|
+
settingsScope = scope
|
|
41
42
|
liveConfig = Config(scope.get() || baseConfig)
|
|
42
43
|
const stop = scope.watch((next) => {
|
|
43
44
|
liveConfig = Config(next || baseConfig)
|
|
@@ -45,16 +46,25 @@ export function apply(ctx, config) {
|
|
|
45
46
|
})
|
|
46
47
|
saveConfigImpl = async (patch) => {
|
|
47
48
|
const result = await scope.update(patch)
|
|
48
|
-
// Settings watchers are serialized asynchronously; refresh the snapshot
|
|
49
|
-
// synchronously as well so a following request sees the new allowlist.
|
|
50
49
|
liveConfig = Config(scope.get() || baseConfig)
|
|
51
50
|
return result
|
|
52
51
|
}
|
|
53
|
-
|
|
52
|
+
ownerCtx.effect(() => () => {
|
|
53
|
+
settingsScope = undefined
|
|
54
54
|
saveConfigImpl = undefined
|
|
55
55
|
stop()
|
|
56
56
|
}, 'dsh-model-sync: settings')
|
|
57
|
-
|
|
57
|
+
return true
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let settings
|
|
61
|
+
try { settings = ctx.get('settings') } catch {}
|
|
62
|
+
if (!bindSettings(settings, ctx)) {
|
|
63
|
+
ctx.inject(['settings'], (sctx) => {
|
|
64
|
+
bindSettings(sctx.settings, sctx)
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
58
68
|
|
|
59
69
|
const service = createProviderService(ctx)
|
|
60
70
|
const synchronizer = createModelSynchronizer(ctx, { getConfig: () => liveConfig, saveConfig })
|