@wcstack/state 1.30.0 → 1.32.0

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.
@@ -388,16 +388,33 @@ const fix = (options) => {
388
388
  /**
389
389
  * Locale number filter - formats number according to locale.
390
390
  *
391
+ * ロケール依存フィルタ(`locale` / `date` / `time` / `datetime`)は
392
+ * **明示引数だけを構築時に確定し、既定の `config.locale` は適用のたびに読む**。
393
+ *
394
+ * 以前は `options?.[0] ?? config.locale` を返り値の関数の**外**で解決していた。
395
+ * フィルタ関数はバインド構築時に一度だけ作られるので、これはロケールを
396
+ * クロージャに焼き込むことを意味する。`config.locale` の確定がバインド構築より
397
+ * 遅れると、それ以降どう直しても「同じページの中で日付だけ既定ロケール」が
398
+ * 永続し、しかも `config.locale` は依存グラフに載らないので再描画で回復もしない。
399
+ * 症状(日付だけ英語)は原因(起動順序)から遠く、追いにくい。
400
+ *
401
+ * 適用のたびに読めば、少なくとも**再適用されたバインドは回復する**。ロケールは
402
+ * 起動時に確定する前提(docs/i18n-design.md D1)なので通常この差は現れず、
403
+ * これは順序事故から復帰できるようにするための保険である。
404
+ *
405
+ * 明示引数(`|date(ja-JP)`)は構築時に固定でよい — バインド式の一部であり、
406
+ * 実行中に変わらない。
407
+ *
391
408
  * @param options - Array with locale string as first element (default: config.locale)
392
409
  * @returns Filter function that returns localized number string
393
410
  */
394
411
  const locale = (options) => {
395
- const opt = options?.[0] ?? config.locale;
412
+ const explicit = options?.[0];
396
413
  return (value) => {
397
414
  if (typeof value !== 'number') {
398
415
  valueMustBeNumber('locale');
399
416
  }
400
- return value.toLocaleString(opt);
417
+ return value.toLocaleString(explicit ?? config.locale);
401
418
  };
402
419
  };
403
420
  /**
@@ -710,12 +727,13 @@ const truncate = (options) => {
710
727
  * @returns Filter function that returns date string
711
728
  */
712
729
  const date = (options) => {
713
- const opt = options?.[0] ?? config.locale;
730
+ // 既定ロケールは適用のたびに読む(`locale` フィルタの注記を参照)
731
+ const explicit = options?.[0];
714
732
  return (value) => {
715
733
  if (!(value instanceof Date)) {
716
734
  valueMustBeDate('date');
717
735
  }
718
- return value.toLocaleDateString(opt);
736
+ return value.toLocaleDateString(explicit ?? config.locale);
719
737
  };
720
738
  };
721
739
  /**
@@ -725,12 +743,13 @@ const date = (options) => {
725
743
  * @returns Filter function that returns time string
726
744
  */
727
745
  const time = (options) => {
728
- const opt = options?.[0] ?? config.locale;
746
+ // 既定ロケールは適用のたびに読む(`locale` フィルタの注記を参照)
747
+ const explicit = options?.[0];
729
748
  return (value) => {
730
749
  if (!(value instanceof Date)) {
731
750
  valueMustBeDate('time');
732
751
  }
733
- return value.toLocaleTimeString(opt);
752
+ return value.toLocaleTimeString(explicit ?? config.locale);
734
753
  };
735
754
  };
736
755
  /**
@@ -740,12 +759,13 @@ const time = (options) => {
740
759
  * @returns Filter function that returns datetime string
741
760
  */
742
761
  const datetime = (options) => {
743
- const opt = options?.[0] ?? config.locale;
762
+ // 既定ロケールは適用のたびに読む(`locale` フィルタの注記を参照)
763
+ const explicit = options?.[0];
744
764
  return (value) => {
745
765
  if (!(value instanceof Date)) {
746
766
  valueMustBeDate('datetime');
747
767
  }
748
- return value.toLocaleString(opt);
768
+ return value.toLocaleString(explicit ?? config.locale);
749
769
  };
750
770
  };
751
771
  /**
@@ -614,16 +614,33 @@ const fix = (options) => {
614
614
  /**
615
615
  * Locale number filter - formats number according to locale.
616
616
  *
617
+ * ロケール依存フィルタ(`locale` / `date` / `time` / `datetime`)は
618
+ * **明示引数だけを構築時に確定し、既定の `config.locale` は適用のたびに読む**。
619
+ *
620
+ * 以前は `options?.[0] ?? config.locale` を返り値の関数の**外**で解決していた。
621
+ * フィルタ関数はバインド構築時に一度だけ作られるので、これはロケールを
622
+ * クロージャに焼き込むことを意味する。`config.locale` の確定がバインド構築より
623
+ * 遅れると、それ以降どう直しても「同じページの中で日付だけ既定ロケール」が
624
+ * 永続し、しかも `config.locale` は依存グラフに載らないので再描画で回復もしない。
625
+ * 症状(日付だけ英語)は原因(起動順序)から遠く、追いにくい。
626
+ *
627
+ * 適用のたびに読めば、少なくとも**再適用されたバインドは回復する**。ロケールは
628
+ * 起動時に確定する前提(docs/i18n-design.md D1)なので通常この差は現れず、
629
+ * これは順序事故から復帰できるようにするための保険である。
630
+ *
631
+ * 明示引数(`|date(ja-JP)`)は構築時に固定でよい — バインド式の一部であり、
632
+ * 実行中に変わらない。
633
+ *
617
634
  * @param options - Array with locale string as first element (default: config.locale)
618
635
  * @returns Filter function that returns localized number string
619
636
  */
620
637
  const locale = (options) => {
621
- const opt = options?.[0] ?? config.locale;
638
+ const explicit = options?.[0];
622
639
  return (value) => {
623
640
  if (typeof value !== 'number') {
624
641
  valueMustBeNumber('locale');
625
642
  }
626
- return value.toLocaleString(opt);
643
+ return value.toLocaleString(explicit ?? config.locale);
627
644
  };
628
645
  };
629
646
  /**
@@ -936,12 +953,13 @@ const truncate = (options) => {
936
953
  * @returns Filter function that returns date string
937
954
  */
938
955
  const date = (options) => {
939
- const opt = options?.[0] ?? config.locale;
956
+ // 既定ロケールは適用のたびに読む(`locale` フィルタの注記を参照)
957
+ const explicit = options?.[0];
940
958
  return (value) => {
941
959
  if (!(value instanceof Date)) {
942
960
  valueMustBeDate('date');
943
961
  }
944
- return value.toLocaleDateString(opt);
962
+ return value.toLocaleDateString(explicit ?? config.locale);
945
963
  };
946
964
  };
947
965
  /**
@@ -951,12 +969,13 @@ const date = (options) => {
951
969
  * @returns Filter function that returns time string
952
970
  */
953
971
  const time = (options) => {
954
- const opt = options?.[0] ?? config.locale;
972
+ // 既定ロケールは適用のたびに読む(`locale` フィルタの注記を参照)
973
+ const explicit = options?.[0];
955
974
  return (value) => {
956
975
  if (!(value instanceof Date)) {
957
976
  valueMustBeDate('time');
958
977
  }
959
- return value.toLocaleTimeString(opt);
978
+ return value.toLocaleTimeString(explicit ?? config.locale);
960
979
  };
961
980
  };
962
981
  /**
@@ -966,12 +985,13 @@ const time = (options) => {
966
985
  * @returns Filter function that returns datetime string
967
986
  */
968
987
  const datetime = (options) => {
969
- const opt = options?.[0] ?? config.locale;
988
+ // 既定ロケールは適用のたびに読む(`locale` フィルタの注記を参照)
989
+ const explicit = options?.[0];
970
990
  return (value) => {
971
991
  if (!(value instanceof Date)) {
972
992
  valueMustBeDate('datetime');
973
993
  }
974
- return value.toLocaleString(opt);
994
+ return value.toLocaleString(explicit ?? config.locale);
975
995
  };
976
996
  };
977
997
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wcstack/state",
3
- "version": "1.30.0",
3
+ "version": "1.32.0",
4
4
  "description": "Reactive state management with declarative data binding for Web Components. Zero dependencies, buildless.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.esm.js",