tsdf 8.0.0-beta.15 → 8.0.0-beta.16

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/main.cjs CHANGED
@@ -1788,7 +1788,9 @@ function newTSDFListQueryStore({
1788
1788
  });
1789
1789
  return useModifyResult(result);
1790
1790
  }
1791
- function updateItemState(itemIds, produceNewData, ifNothingWasUpdated) {
1791
+ function updateItemState(itemIds, produceNewData, {
1792
+ ifNothingWasUpdated
1793
+ } = {}) {
1792
1794
  const itemKeys = getItemsKeyArray(itemIds);
1793
1795
  let someItemWasUpdated = false;
1794
1796
  store.batch(
@@ -1813,7 +1815,9 @@ function newTSDFListQueryStore({
1813
1815
  );
1814
1816
  return someItemWasUpdated;
1815
1817
  }
1816
- function addItemToState(itemPayload, data) {
1818
+ function addItemToState(itemPayload, data, {
1819
+ addItemToQueries
1820
+ } = {}) {
1817
1821
  const itemKey = getItemKey(itemPayload);
1818
1822
  store.produceState(
1819
1823
  (draftState) => {
@@ -1825,6 +1829,29 @@ function newTSDFListQueryStore({
1825
1829
  error: null,
1826
1830
  payload: (0, import_json2.klona)(itemPayload)
1827
1831
  };
1832
+ if (addItemToQueries) {
1833
+ const queries = getQueriesKeyArray(addItemToQueries.queries);
1834
+ for (const { key } of queries) {
1835
+ if (draftState.queries[key]) {
1836
+ const queryState = draftState.queries[key];
1837
+ if (!queryState)
1838
+ continue;
1839
+ if (addItemToQueries.appendTo === "start") {
1840
+ queryState.items.unshift(itemKey);
1841
+ } else if (addItemToQueries.appendTo === "end") {
1842
+ queryState.items.push(itemKey);
1843
+ } else {
1844
+ const index = addItemToQueries.appendTo(
1845
+ filterAndMap(
1846
+ queryState.items,
1847
+ (itemKey2, ignore2) => draftState.itemQueries[itemKey2]?.payload || ignore2
1848
+ )
1849
+ );
1850
+ queryState.items.splice(index, 0, itemKey);
1851
+ }
1852
+ }
1853
+ }
1854
+ }
1828
1855
  },
1829
1856
  { action: { type: "create-item-state", itemPayload } }
1830
1857
  );
package/dist/main.d.ts CHANGED
@@ -282,8 +282,15 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
282
282
  returnIdleStatus?: boolean | undefined;
283
283
  returnRefetchingStatus?: boolean | undefined;
284
284
  }) => readonly TSFDUseListItemReturn<SelectedItem_3, NError, ItemPayload>[];
285
- addItemToState: (itemPayload: ItemPayload, data: ItemState) => void;
286
- updateItemState: (itemIds: ItemPayload | ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[], produceNewData: (draftData: ItemState, itemPayload: ItemPayload) => void | ItemState, ifNothingWasUpdated?: () => void) => boolean;
285
+ addItemToState: (itemPayload: ItemPayload, data: ItemState, { addItemToQueries, }?: {
286
+ addItemToQueries?: {
287
+ queries: QueryPayload | QueryPayload[] | ((params: QueryPayload, data: TSFDListQuery<NError, QueryPayload>, queryKey: string) => boolean);
288
+ appendTo: "start" | "end" | ((itemsPayload: ItemPayload[]) => number);
289
+ } | undefined;
290
+ }) => void;
291
+ updateItemState: (itemIds: ItemPayload | ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[], produceNewData: (draftData: ItemState, itemPayload: ItemPayload) => void | ItemState, { ifNothingWasUpdated, }?: {
292
+ ifNothingWasUpdated?: (() => void) | undefined;
293
+ }) => boolean;
287
294
  startItemMutation: (itemId: ItemPayload | ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[]) => () => void;
288
295
  };
289
296
  type TSFDListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = ReturnType<typeof newTSDFListQueryStore<ItemState, NError, QueryPayload, ItemPayload>>;
package/dist/main.js CHANGED
@@ -1754,7 +1754,9 @@ function newTSDFListQueryStore({
1754
1754
  });
1755
1755
  return useModifyResult(result);
1756
1756
  }
1757
- function updateItemState(itemIds, produceNewData, ifNothingWasUpdated) {
1757
+ function updateItemState(itemIds, produceNewData, {
1758
+ ifNothingWasUpdated
1759
+ } = {}) {
1758
1760
  const itemKeys = getItemsKeyArray(itemIds);
1759
1761
  let someItemWasUpdated = false;
1760
1762
  store.batch(
@@ -1779,7 +1781,9 @@ function newTSDFListQueryStore({
1779
1781
  );
1780
1782
  return someItemWasUpdated;
1781
1783
  }
1782
- function addItemToState(itemPayload, data) {
1784
+ function addItemToState(itemPayload, data, {
1785
+ addItemToQueries
1786
+ } = {}) {
1783
1787
  const itemKey = getItemKey(itemPayload);
1784
1788
  store.produceState(
1785
1789
  (draftState) => {
@@ -1791,6 +1795,29 @@ function newTSDFListQueryStore({
1791
1795
  error: null,
1792
1796
  payload: klona2(itemPayload)
1793
1797
  };
1798
+ if (addItemToQueries) {
1799
+ const queries = getQueriesKeyArray(addItemToQueries.queries);
1800
+ for (const { key } of queries) {
1801
+ if (draftState.queries[key]) {
1802
+ const queryState = draftState.queries[key];
1803
+ if (!queryState)
1804
+ continue;
1805
+ if (addItemToQueries.appendTo === "start") {
1806
+ queryState.items.unshift(itemKey);
1807
+ } else if (addItemToQueries.appendTo === "end") {
1808
+ queryState.items.push(itemKey);
1809
+ } else {
1810
+ const index = addItemToQueries.appendTo(
1811
+ filterAndMap(
1812
+ queryState.items,
1813
+ (itemKey2, ignore2) => draftState.itemQueries[itemKey2]?.payload || ignore2
1814
+ )
1815
+ );
1816
+ queryState.items.splice(index, 0, itemKey);
1817
+ }
1818
+ }
1819
+ }
1820
+ }
1794
1821
  },
1795
1822
  { action: { type: "create-item-state", itemPayload } }
1796
1823
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdf",
3
- "version": "8.0.0-beta.15",
3
+ "version": "8.0.0-beta.16",
4
4
  "description": "A data fetching solution based on t-state",
5
5
  "license": "MIT",
6
6
  "author": "Lucas Santos",