@gridkitjs/core 0.0.0-dev-20261109083020 → 0.0.0-dev-20261109125321

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/dist/index.d.ts CHANGED
@@ -50,8 +50,10 @@ interface GridControllerOptions<Row, Node = string> extends GridOptions<Row>, Se
50
50
  *
51
51
  * Every action follows the same steps: work out the next value; stop if it
52
52
  * is the very object the slice already holds; keep it, unless the slice is
53
- * controlled; report it through the slice's callback; then call every
54
- * subscriber, synchronously. The setters (`setColumnSort` and the like) also
53
+ * controlled; report it through the slice's callback; then, if the state
54
+ * changed, call every subscriber, synchronously. A controlled slice's state
55
+ * changes only when the next `setOptions` carries the value, so an action on
56
+ * it reports without calling subscribers. The setters (`setColumnSort` and the like) also
55
57
  * stop for a value equal to the current one, so restoring what is already
56
58
  * there reports nothing.
57
59
  *
@@ -76,8 +78,9 @@ interface GridController<Row, Node = string> {
76
78
  /** What the user is looking at — see `resolveGridView`. The same object until something in it changes. */
77
79
  readonly getView: () => GridView<Row, Node>;
78
80
  /**
79
- * Calls `listener` after each action that got as far as reporting a
80
- * change. Returns the function that unsubscribes it.
81
+ * Calls `listener` after each action that changed the state, so
82
+ * `getState()` returns a new object whenever it runs. Returns the function
83
+ * that unsubscribes it.
81
84
  */
82
85
  readonly subscribe: (listener: () => void) => () => void;
83
86
  /**
@@ -85,7 +88,8 @@ interface GridController<Row, Node = string> {
85
88
  * `serializeGridState` and back through JSON. Every slice given is set as
86
89
  * its own `set*` action would set it, so each that changes fires its
87
90
  * callback and a controlled one only asks; slices left out keep their value.
88
- * Subscribers are called once, after every slice is in place, and a
91
+ * Subscribers are called once, after every slice is in place, if any
92
+ * changed, and a
89
93
  * restored pagination is kept even when the same call changed the sort,
90
94
  * filter or grouping that would otherwise send it back to the first page.
91
95
  * A slice that throws stops the restore there, after the slices before it
@@ -167,7 +171,7 @@ interface GridController<Row, Node = string> {
167
171
  /**
168
172
  * Lets go of every row, column and cell selection at once, as Escape does:
169
173
  * one change, so each selection that changes fires its callback and then
170
- * subscribers are called once.
174
+ * subscribers are called once, if the state changed.
171
175
  */
172
176
  readonly clearSelection: () => void;
173
177
  /** Replaces the selected column ids as given — see `setRowSelection`. */
@@ -1905,8 +1909,11 @@ interface GridOptions<Row> {
1905
1909
  contextMenu?: boolean | GridContextMenuOptions<Row> | undefined;
1906
1910
  /**
1907
1911
  * Called when the grid's context menu opens or closes, with where. A menu
1908
- * opened in place of another reports that one closing first. The open
1909
- * state is the renderer's to keep, so no option holds it.
1912
+ * opened in place of another reports that one closing first. It also
1913
+ * reports closing when a panel opens in its place (before the command of
1914
+ * a menu item that opened it runs), when the grid unmounts and when
1915
+ * `contextMenu` is turned off while it is open. The open state is the renderer's to keep, so no
1916
+ * option holds it.
1910
1917
  */
1911
1918
  onContextMenuOpenChange?: ((event: ContextMenuOpenChangeEvent) => void) | undefined;
1912
1919
  /**
package/dist/index.js CHANGED
@@ -1872,9 +1872,11 @@ function createGridController(initial) {
1872
1872
  }
1873
1873
  }
1874
1874
  function refresh(keepPage = false) {
1875
+ const before = state;
1875
1876
  const next = followPagingInputs(resolveSlices(), keepPage);
1876
1877
  state = SLICE_KEYS.every((key) => next[key] === state[key]) ? state : next;
1877
1878
  storeShownPage();
1879
+ return state !== before;
1878
1880
  }
1879
1881
  function followPagingInputs(next, keepPage) {
1880
1882
  const inputs = pagingInputsOf(next, options);
@@ -1918,9 +1920,11 @@ function createGridController(initial) {
1918
1920
  mode.held.push(report);
1919
1921
  return;
1920
1922
  }
1921
- refresh();
1923
+ const changed = refresh();
1922
1924
  report();
1923
- notify();
1925
+ if (changed) {
1926
+ notify();
1927
+ }
1924
1928
  }
1925
1929
  function transaction(run) {
1926
1930
  if (mode.kind === "transaction") {
@@ -1937,11 +1941,11 @@ function createGridController(initial) {
1937
1941
  run();
1938
1942
  } finally {
1939
1943
  mode = IDLE;
1940
- refresh(current.pageAsked);
1944
+ const changed = refresh(current.pageAsked);
1941
1945
  for (const report of current.held) {
1942
1946
  report();
1943
1947
  }
1944
- if (current.held.length > 0) {
1948
+ if (changed) {
1945
1949
  notify();
1946
1950
  }
1947
1951
  }