tinybase 3.2.0-beta.0 → 3.3.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.
- package/bin/cli.js +1 -1
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/cjs/checkpoints.cjs +1 -1
- package/lib/cjs/checkpoints.cjs.gz +0 -0
- package/lib/cjs/indexes.cjs +1 -1
- package/lib/cjs/indexes.cjs.gz +0 -0
- package/lib/cjs/metrics.cjs +1 -1
- package/lib/cjs/metrics.cjs.gz +0 -0
- package/lib/cjs/persisters.cjs +1 -1
- package/lib/cjs/persisters.cjs.gz +0 -0
- package/lib/cjs/queries.cjs +1 -1
- package/lib/cjs/queries.cjs.gz +0 -0
- package/lib/cjs/relationships.cjs +1 -1
- package/lib/cjs/relationships.cjs.gz +0 -0
- package/lib/cjs/store.cjs +1 -1
- package/lib/cjs/store.cjs.gz +0 -0
- package/lib/cjs/tinybase.cjs +1 -1
- package/lib/cjs/tinybase.cjs.gz +0 -0
- package/lib/cjs/tools.cjs +1 -1
- package/lib/cjs/tools.cjs.gz +0 -0
- package/lib/cjs/ui-react.cjs +1 -1
- package/lib/cjs/ui-react.cjs.gz +0 -0
- package/lib/cjs-es6/checkpoints.cjs +1 -1
- package/lib/cjs-es6/checkpoints.cjs.gz +0 -0
- package/lib/cjs-es6/indexes.cjs +1 -1
- package/lib/cjs-es6/indexes.cjs.gz +0 -0
- package/lib/cjs-es6/metrics.cjs +1 -1
- package/lib/cjs-es6/metrics.cjs.gz +0 -0
- package/lib/cjs-es6/persisters.cjs +1 -1
- package/lib/cjs-es6/persisters.cjs.gz +0 -0
- package/lib/cjs-es6/queries.cjs +1 -1
- package/lib/cjs-es6/queries.cjs.gz +0 -0
- package/lib/cjs-es6/relationships.cjs +1 -1
- package/lib/cjs-es6/relationships.cjs.gz +0 -0
- package/lib/cjs-es6/store.cjs +1 -1
- package/lib/cjs-es6/store.cjs.gz +0 -0
- package/lib/cjs-es6/tinybase.cjs +1 -1
- package/lib/cjs-es6/tinybase.cjs.gz +0 -0
- package/lib/cjs-es6/tools.cjs +1 -1
- package/lib/cjs-es6/tools.cjs.gz +0 -0
- package/lib/cjs-es6/ui-react.cjs +1 -1
- package/lib/cjs-es6/ui-react.cjs.gz +0 -0
- package/lib/debug/checkpoints.js +2 -2
- package/lib/debug/indexes.js +2 -2
- package/lib/debug/metrics.js +2 -2
- package/lib/debug/persisters.js +2 -2
- package/lib/debug/queries.js +1 -1
- package/lib/debug/relationships.js +2 -2
- package/lib/debug/store.js +89 -48
- package/lib/debug/tinybase.js +92 -51
- package/lib/debug/tools.js +106 -5
- package/lib/debug/ui-react.js +27 -2
- package/lib/es6/checkpoints.js +1 -1
- package/lib/es6/checkpoints.js.gz +0 -0
- package/lib/es6/indexes.js +1 -1
- package/lib/es6/indexes.js.gz +0 -0
- package/lib/es6/metrics.js +1 -1
- package/lib/es6/metrics.js.gz +0 -0
- package/lib/es6/persisters.js +1 -1
- package/lib/es6/persisters.js.gz +0 -0
- package/lib/es6/queries.js +1 -1
- package/lib/es6/queries.js.gz +0 -0
- package/lib/es6/relationships.js +1 -1
- package/lib/es6/relationships.js.gz +0 -0
- package/lib/es6/store.js +1 -1
- package/lib/es6/store.js.gz +0 -0
- package/lib/es6/tinybase.js +1 -1
- package/lib/es6/tinybase.js.gz +0 -0
- package/lib/es6/tools.js +1 -1
- package/lib/es6/tools.js.gz +0 -0
- package/lib/es6/ui-react.js +1 -1
- package/lib/es6/ui-react.js.gz +0 -0
- package/lib/indexes.js +1 -1
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.js +1 -1
- package/lib/metrics.js.gz +0 -0
- package/lib/persisters.js +1 -1
- package/lib/persisters.js.gz +0 -0
- package/lib/queries.js +1 -1
- package/lib/queries.js.gz +0 -0
- package/lib/relationships.js +1 -1
- package/lib/relationships.js.gz +0 -0
- package/lib/store.js +1 -1
- package/lib/store.js.gz +0 -0
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/tools.js +1 -1
- package/lib/tools.js.gz +0 -0
- package/lib/types/store.d.ts +386 -30
- package/lib/types/tools.d.ts +2 -2
- package/lib/types/ui-react.d.ts +167 -0
- package/lib/types/with-schemas/store.d.ts +496 -37
- package/lib/types/with-schemas/tools.d.ts +2 -2
- package/lib/types/with-schemas/ui-react.d.ts +193 -5
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/checkpoints.js +1 -1
- package/lib/umd/checkpoints.js.gz +0 -0
- package/lib/umd/indexes.js +1 -1
- package/lib/umd/indexes.js.gz +0 -0
- package/lib/umd/metrics.js +1 -1
- package/lib/umd/metrics.js.gz +0 -0
- package/lib/umd/persisters.js +1 -1
- package/lib/umd/persisters.js.gz +0 -0
- package/lib/umd/queries.js +1 -1
- package/lib/umd/queries.js.gz +0 -0
- package/lib/umd/relationships.js +1 -1
- package/lib/umd/relationships.js.gz +0 -0
- package/lib/umd/store.js +1 -1
- package/lib/umd/store.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/tools.js +1 -1
- package/lib/umd/tools.js.gz +0 -0
- package/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/lib/umd-es6/checkpoints.js +1 -1
- package/lib/umd-es6/checkpoints.js.gz +0 -0
- package/lib/umd-es6/indexes.js +1 -1
- package/lib/umd-es6/indexes.js.gz +0 -0
- package/lib/umd-es6/metrics.js +1 -1
- package/lib/umd-es6/metrics.js.gz +0 -0
- package/lib/umd-es6/persisters.js +1 -1
- package/lib/umd-es6/persisters.js.gz +0 -0
- package/lib/umd-es6/queries.js +1 -1
- package/lib/umd-es6/queries.js.gz +0 -0
- package/lib/umd-es6/relationships.js +1 -1
- package/lib/umd-es6/relationships.js.gz +0 -0
- package/lib/umd-es6/store.js +1 -1
- package/lib/umd-es6/store.js.gz +0 -0
- package/lib/umd-es6/tinybase.js +1 -1
- package/lib/umd-es6/tinybase.js.gz +0 -0
- package/lib/umd-es6/tools.js +1 -1
- package/lib/umd-es6/tools.js.gz +0 -0
- package/lib/umd-es6/ui-react.js +1 -1
- package/lib/umd-es6/ui-react.js.gz +0 -0
- package/package.json +52 -28
- package/readme.md +14 -14
package/lib/types/ui-react.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
SortedRowIdsListener,
|
|
38
38
|
Store,
|
|
39
39
|
Table,
|
|
40
|
+
TableCellIdsListener,
|
|
40
41
|
TableIdsListener,
|
|
41
42
|
TableListener,
|
|
42
43
|
Tables,
|
|
@@ -580,6 +581,92 @@ export function useTableIds(storeOrStoreId?: StoreOrStoreId): Ids;
|
|
|
580
581
|
*/
|
|
581
582
|
export function useTable(tableId: Id, storeOrStoreId?: StoreOrStoreId): Table;
|
|
582
583
|
|
|
584
|
+
/**
|
|
585
|
+
* The useTableCellIds hook returns the Ids of every Cell used across the whole
|
|
586
|
+
* Table, and registers a listener so that any changes to that result will cause
|
|
587
|
+
* a re-render.
|
|
588
|
+
*
|
|
589
|
+
* A Provider component is used to wrap part of an application in a context, and
|
|
590
|
+
* it can contain a default Store or a set of Store objects named by Id. The
|
|
591
|
+
* useTableCellIds hook lets you indicate which Store to get data for: omit the
|
|
592
|
+
* optional final parameter for the default context Store, provide an Id for a
|
|
593
|
+
* named context Store, or provide a Store explicitly by reference.
|
|
594
|
+
*
|
|
595
|
+
* When first rendered, this hook will create a listener so that changes to the
|
|
596
|
+
* Table Cell Ids will cause a re-render. When the component containing this
|
|
597
|
+
* hook is unmounted, the listener will be automatically removed.
|
|
598
|
+
*
|
|
599
|
+
* @param tableId The Id of the Table in the Store.
|
|
600
|
+
* @param storeOrStoreId The Store to be accessed: omit for the default context
|
|
601
|
+
* Store, provide an Id for a named context Store, or provide an explicit
|
|
602
|
+
* reference.
|
|
603
|
+
* @returns An array of the Ids of every Cell used across the whole Table.
|
|
604
|
+
* @example
|
|
605
|
+
* This example creates a Store outside the application, which is used in the
|
|
606
|
+
* useTableCellIds hook by reference. A change to the data in the Store
|
|
607
|
+
* re-renders the component.
|
|
608
|
+
*
|
|
609
|
+
* ```jsx
|
|
610
|
+
* const store = createStore().setCell('pets', 'fido', 'color', 'brown');
|
|
611
|
+
* const App = () => (
|
|
612
|
+
* <span>{JSON.stringify(useTableCellIds('pets', store))}</span>
|
|
613
|
+
* );
|
|
614
|
+
*
|
|
615
|
+
* const app = document.createElement('div');
|
|
616
|
+
* ReactDOMClient.createRoot(app).render(<App />); // !act
|
|
617
|
+
* console.log(app.innerHTML);
|
|
618
|
+
* // -> '<span>["color"]</span>'
|
|
619
|
+
*
|
|
620
|
+
* store.setCell('pets', 'felix', 'species', 'cat'); // !act
|
|
621
|
+
* console.log(app.innerHTML);
|
|
622
|
+
* // -> '<span>["color","species"]</span>'
|
|
623
|
+
* ```
|
|
624
|
+
* @example
|
|
625
|
+
* This example creates a Provider context into which a default Store is
|
|
626
|
+
* provided. A component within it then uses the useTableCellIds hook.
|
|
627
|
+
*
|
|
628
|
+
* ```jsx
|
|
629
|
+
* const App = ({store}) => (
|
|
630
|
+
* <Provider store={store}>
|
|
631
|
+
* <Pane />
|
|
632
|
+
* </Provider>
|
|
633
|
+
* );
|
|
634
|
+
* const Pane = () => <span>{JSON.stringify(useTableCellIds('pets'))}</span>;
|
|
635
|
+
*
|
|
636
|
+
* const store = createStore().setCell('pets', 'fido', 'color', 'brown');
|
|
637
|
+
* const app = document.createElement('div');
|
|
638
|
+
* ReactDOMClient.createRoot(app).render(<App store={store} />); // !act
|
|
639
|
+
* console.log(app.innerHTML);
|
|
640
|
+
* // -> '<span>["color"]</span>'
|
|
641
|
+
* ```
|
|
642
|
+
* @example
|
|
643
|
+
* This example creates a Provider context into which a Store is provided, named
|
|
644
|
+
* by Id. A component within it then uses the useTableCellIds hook.
|
|
645
|
+
*
|
|
646
|
+
* ```jsx
|
|
647
|
+
* const App = ({store}) => (
|
|
648
|
+
* <Provider storesById={{petStore: store}}>
|
|
649
|
+
* <Pane />
|
|
650
|
+
* </Provider>
|
|
651
|
+
* );
|
|
652
|
+
* const Pane = () => (
|
|
653
|
+
* <span>{JSON.stringify(useTableCellIds('pets', 'petStore'))}</span>
|
|
654
|
+
* );
|
|
655
|
+
*
|
|
656
|
+
* const store = createStore().setCell('pets', 'fido', 'color', 'brown');
|
|
657
|
+
* const app = document.createElement('div');
|
|
658
|
+
* ReactDOMClient.createRoot(app).render(<App store={store} />); // !act
|
|
659
|
+
* console.log(app.innerHTML);
|
|
660
|
+
* // -> '<span>["color"]</span>'
|
|
661
|
+
* ```
|
|
662
|
+
* @category Store hooks
|
|
663
|
+
* @since v3.3
|
|
664
|
+
*/
|
|
665
|
+
export function useTableCellIds(
|
|
666
|
+
tableId: Id,
|
|
667
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
668
|
+
): Ids;
|
|
669
|
+
|
|
583
670
|
/**
|
|
584
671
|
* The useRowIds hook returns the Ids of every Row in a given Table, and
|
|
585
672
|
* registers a listener so that any changes to that result will cause a
|
|
@@ -1563,6 +1650,13 @@ export function useSetRowCallback<Parameter>(
|
|
|
1563
1650
|
* hook's `storeOrStoreId` parameter) is always automatically used as a hook
|
|
1564
1651
|
* dependency for the callback.
|
|
1565
1652
|
*
|
|
1653
|
+
* The `reuseRowIds` parameter defaults to `true`, which means that if you
|
|
1654
|
+
* delete a Row and then add another, the Id will be re-used - unless you delete
|
|
1655
|
+
* the entire Table, in which case all Row Ids will reset. Otherwise, if you
|
|
1656
|
+
* specify `reuseRowIds` to be `false`, then the Id will be a monotonically
|
|
1657
|
+
* increasing string representation of an increasing integer, regardless of any
|
|
1658
|
+
* you may have previously deleted.
|
|
1659
|
+
*
|
|
1566
1660
|
* @param tableId The Id of the Table in the Store.
|
|
1567
1661
|
* @param getRow A function which returns the Row object that will be used to
|
|
1568
1662
|
* update the Store, based on the parameter the callback will receive (and which
|
|
@@ -1578,6 +1672,9 @@ export function useSetRowCallback<Parameter>(
|
|
|
1578
1672
|
* @param thenDeps An optional array of dependencies for the `then` function,
|
|
1579
1673
|
* which, if any change, result in the regeneration of the callback. This
|
|
1580
1674
|
* parameter defaults to an empty array.
|
|
1675
|
+
* @param reuseRowIds Whether Ids should be recycled from previously deleted Row
|
|
1676
|
+
* objects, defaulting to `true`.
|
|
1677
|
+
*
|
|
1581
1678
|
* @returns A parameterized callback for subsequent use.
|
|
1582
1679
|
* @example
|
|
1583
1680
|
* This example uses the useAddRowCallback hook to create an event handler which
|
|
@@ -1622,6 +1719,7 @@ export function useAddRowCallback<Parameter>(
|
|
|
1622
1719
|
storeOrStoreId?: StoreOrStoreId,
|
|
1623
1720
|
then?: (rowId: Id | undefined, store: Store, row: Row) => void,
|
|
1624
1721
|
thenDeps?: React.DependencyList,
|
|
1722
|
+
reuseRowIds?: boolean,
|
|
1625
1723
|
): ParameterizedCallback<Parameter>;
|
|
1626
1724
|
|
|
1627
1725
|
/**
|
|
@@ -2696,6 +2794,75 @@ export function useTableListener(
|
|
|
2696
2794
|
storeOrStoreId?: StoreOrStoreId,
|
|
2697
2795
|
): void;
|
|
2698
2796
|
|
|
2797
|
+
/**
|
|
2798
|
+
* The useTableCellIdsListener hook registers a listener function with a Store
|
|
2799
|
+
* that will be called whenever the Cell Ids that appear anywhere in a Table
|
|
2800
|
+
* change.
|
|
2801
|
+
*
|
|
2802
|
+
* This hook is useful for situations where a component needs to register its
|
|
2803
|
+
* own specific listener to do more than simply tracking the value (which is
|
|
2804
|
+
* more easily done with the useTableCellIds hook).
|
|
2805
|
+
*
|
|
2806
|
+
* You can either listen to a single Table (by specifying its Id as the method's
|
|
2807
|
+
* first parameter) or changes to any Table (by providing `null`).
|
|
2808
|
+
*
|
|
2809
|
+
* Unlike the addTableCellIdsListener method, which returns a listener Id and
|
|
2810
|
+
* requires you to remove it manually, the useTableCellIdsListener hook manages
|
|
2811
|
+
* this lifecycle for you: when the listener changes (per its `listenerDeps`
|
|
2812
|
+
* dependencies) or the component unmounts, the listener on the underlying Store
|
|
2813
|
+
* will be deleted.
|
|
2814
|
+
*
|
|
2815
|
+
* @param tableId The Id of the Table to listen to, or `null` as a wildcard.
|
|
2816
|
+
* @param listener The function that will be called whenever the Cell Ids that
|
|
2817
|
+
* appear anywhere in a Table change.
|
|
2818
|
+
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
2819
|
+
* function, which, if any change, result in the re-registration of the
|
|
2820
|
+
* listener. This parameter defaults to an empty array.
|
|
2821
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
2822
|
+
* Store data.
|
|
2823
|
+
* @param storeOrStoreId The Store to register the listener with: omit for the
|
|
2824
|
+
* default context Store, provide an Id for a named context Store, or provide an
|
|
2825
|
+
* explicit reference.
|
|
2826
|
+
* @example
|
|
2827
|
+
* This example uses the useTableCellIdsListener hook to create a listener that
|
|
2828
|
+
* is scoped to a single component. When the component is unmounted, the
|
|
2829
|
+
* listener is removed from the Store.
|
|
2830
|
+
*
|
|
2831
|
+
* ```jsx
|
|
2832
|
+
* const App = ({store}) => (
|
|
2833
|
+
* <Provider store={store}>
|
|
2834
|
+
* <Pane />
|
|
2835
|
+
* </Provider>
|
|
2836
|
+
* );
|
|
2837
|
+
* const Pane = () => {
|
|
2838
|
+
* useTableCellIdsListener('pets', () => console.log('Cell Ids changed'));
|
|
2839
|
+
* return <span>App</span>;
|
|
2840
|
+
* };
|
|
2841
|
+
*
|
|
2842
|
+
* const store = createStore().setTables({pets: {fido: {color: 'brown'}}});
|
|
2843
|
+
* const app = document.createElement('div');
|
|
2844
|
+
* const root = ReactDOMClient.createRoot(app);
|
|
2845
|
+
* root.render(<App store={store} />); // !act
|
|
2846
|
+
* console.log(store.getListenerStats().tableCellIds);
|
|
2847
|
+
* // -> 1
|
|
2848
|
+
*
|
|
2849
|
+
* store.setRow('pets', 'felix', {species: 'cat'}); // !act
|
|
2850
|
+
* // -> 'Cell Ids changed'
|
|
2851
|
+
*
|
|
2852
|
+
* root.unmount(); // !act
|
|
2853
|
+
* console.log(store.getListenerStats().rowIds);
|
|
2854
|
+
* // -> 0
|
|
2855
|
+
* ```
|
|
2856
|
+
* @category Store hooks
|
|
2857
|
+
*/
|
|
2858
|
+
export function useTableCellIdsListener(
|
|
2859
|
+
tableId: IdOrNull,
|
|
2860
|
+
listener: TableCellIdsListener,
|
|
2861
|
+
listenerDeps?: React.DependencyList,
|
|
2862
|
+
mutator?: boolean,
|
|
2863
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
2864
|
+
): void;
|
|
2865
|
+
|
|
2699
2866
|
/**
|
|
2700
2867
|
* The useRowIdsListener hook registers a listener function with a Store that
|
|
2701
2868
|
* will be called whenever the Row Ids in a Table change.
|