@magnetarjs/utils
Version:
Magnetar utils like a logger for easier development
33 lines (32 loc) • 1.05 kB
TypeScript
/** Using an actual symbol causes issues in production host apps for whatever reason... */
export declare const storeSplitSymbol = "MAGNETAR_SYMBOL_storeSplit";
/**
* A storeSplit function allows you to apply a different payload between your cache store vs your other stores.
*
* It will let TypeScript know that you're trying to apply the type of whatever you pass to the `cache` key, even though your other stores might receive other values.
*
* ### Example Use Case
* ```ts
* import { storeSplit } from '@magnetarjs/utils'
*
* magnetar.collection('user').doc('1').merge({
* name: 'updated name',
* // ...
* dateUpdated: storeSplit({
* cache: new Date(),
* remote: serverTimestamp(),
* })
* })
* ```
*/
export declare function storeSplit<Payload extends {
cache: any;
[key: string]: any;
}>(payload: Payload): Payload['cache'];
export declare function isStoreSplit(payload: unknown): payload is {
storeSplitSymbol: symbol;
storePayloadDic: {
cache: any;
[key: string]: any;
};
};