@huanlin/dsh-plugin-interpreters 0.2.2 → 0.2.3

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/client.js CHANGED
@@ -905,13 +905,23 @@ var dicts = {
905
905
  var inject = ["slots", "locale", "connection"];
906
906
  function apply(ctx) {
907
907
  ctx.effect(() => ctx.locale.register(NS, { zh, en }), "dsh-interpreters: dictionaries");
908
- const betterLocale = ctx.get("betterLocale");
909
- if (betterLocale) {
910
- ctx.effect(
911
- () => betterLocale.register(NS, dicts),
912
- "interpreters: better-locale override dicts"
913
- );
914
- }
908
+ ctx.effect(() => {
909
+ let dispose;
910
+ const sync = () => {
911
+ dispose?.();
912
+ dispose = void 0;
913
+ const store = ctx.get("betterLocale");
914
+ if (store !== void 0) {
915
+ dispose = store.register(NS, dicts);
916
+ }
917
+ };
918
+ sync();
919
+ const unsubscribe = ctx.locale.subscribe(sync);
920
+ return () => {
921
+ unsubscribe();
922
+ dispose?.();
923
+ };
924
+ }, "interpreters: better-locale override dicts");
915
925
  const controller = new InterpretersCardController();
916
926
  const useSnapshot = bindSnapshotSelector(controller.store);
917
927
  ctx.effect(() => {
@@ -32,14 +32,28 @@ export const inject = ['slots', 'locale', 'connection'];
32
32
  */
33
33
  export function apply(ctx) {
34
34
  ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'dsh-interpreters: dictionaries');
35
- // Opt-in third-language overrides through @huanlin/dsh-plugin-better-locale:
36
- // when installed it publishes `ctx.betterLocale` (the override store) and
37
- // patches LocaleRuntime.lookup to consult it. `ctx.get` is a non-reactive
38
- // read of an optional service, so an absent plugin is a plain no-op.
39
- const betterLocale = ctx.get('betterLocale');
40
- if (betterLocale) {
41
- ctx.effect(() => betterLocale.register(NS, dicts), 'interpreters: better-locale override dicts');
42
- }
35
+ // Opt-in third-language overrides through @huanlin/dsh-plugin-better-locale.
36
+ // Activation-order-safe: ctx.get('betterLocale') is a non-reactive read, so
37
+ // if better-locale activates after us, the initial read returns undefined.
38
+ // We subscribe to ctx.locale better-locale bumps its revision on activation
39
+ // (persisted override) and on every override switch — and re-check on each bump.
40
+ ctx.effect(() => {
41
+ let dispose;
42
+ const sync = () => {
43
+ dispose?.();
44
+ dispose = undefined;
45
+ const store = ctx.get('betterLocale');
46
+ if (store !== undefined) {
47
+ dispose = store.register(NS, dicts);
48
+ }
49
+ };
50
+ sync();
51
+ const unsubscribe = ctx.locale.subscribe(sync);
52
+ return () => {
53
+ unsubscribe();
54
+ dispose?.();
55
+ };
56
+ }, 'interpreters: better-locale override dicts');
43
57
  // The store reads/writes the interpreters config over the plugin's
44
58
  // self-hosted HTTP route (`/interpreters/api/get` + `/interpreters/api/set`).
45
59
  const controller = new InterpretersCardController();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huanlin/dsh-plugin-interpreters",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },