tinybase 3.2.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/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/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/store.js +53 -13
- package/lib/debug/tinybase.js +53 -13
- package/lib/debug/tools.js +93 -1
- package/lib/debug/ui-react.js +24 -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/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 +302 -9
- package/lib/types/tools.d.ts +2 -2
- package/lib/types/ui-react.d.ts +156 -0
- package/lib/types/with-schemas/store.d.ts +405 -16
- package/lib/types/with-schemas/tools.d.ts +2 -2
- package/lib/types/with-schemas/ui-react.d.ts +181 -5
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.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/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 +15 -15
- package/readme.md +2 -2
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
|
|
@@ -2707,6 +2794,75 @@ export function useTableListener(
|
|
|
2707
2794
|
storeOrStoreId?: StoreOrStoreId,
|
|
2708
2795
|
): void;
|
|
2709
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
|
+
|
|
2710
2866
|
/**
|
|
2711
2867
|
* The useRowIdsListener hook registers a listener function with a Store that
|
|
2712
2868
|
* will be called whenever the Row Ids in a Table change.
|