Skip to content

Commit 230ef57

Browse files
committed
TEMP: add dist
1 parent 28c6d5c commit 230ef57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+5327
-10
lines changed

dist/DevTools.d.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
type DevtoolsOptions = {
2+
maxAge?: number;
3+
name?: string;
4+
postTimelineUpdate?: () => void;
5+
preAction?: () => void;
6+
logTrace?: boolean;
7+
remote?: boolean;
8+
};
9+
type DevtoolsSubscriber = (message: {
10+
type: string;
11+
payload: unknown;
12+
state: string;
13+
}) => void;
14+
type DevtoolsConnection = {
15+
send(data: Record<string, unknown>, state: Record<string, unknown>): void;
16+
init(state: Record<string, unknown>): void;
17+
unsubscribe(): void;
18+
subscribe(cb: DevtoolsSubscriber): () => void;
19+
};
20+
declare class DevTools {
21+
private remoteDev?;
22+
private state;
23+
private defaultState;
24+
constructor();
25+
connectViaExtension(options?: DevtoolsOptions): DevtoolsConnection | undefined;
26+
/**
27+
* Registers an action that updated the current state of the storage
28+
*
29+
* @param type - name of the action
30+
* @param payload - data written to the storage
31+
* @param stateChanges - partial state that got updated after the changes
32+
*/
33+
registerAction(type: string, payload: unknown, stateChanges?: Record<string, unknown> | null): void;
34+
initState(initialState?: Record<string, unknown>): void;
35+
/**
36+
* This clears the internal state of the DevTools, preserving the keys included in `keysToPreserve`
37+
*/
38+
clearState(keysToPreserve?: string[]): void;
39+
}
40+
declare const _default: DevTools;
41+
export default _default;
42+
export type { DevtoolsConnection };

dist/DevTools.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
const ERROR_LABEL = 'Onyx DevTools - Error: ';
4+
class DevTools {
5+
constructor() {
6+
this.remoteDev = this.connectViaExtension();
7+
this.state = {};
8+
this.defaultState = {};
9+
}
10+
connectViaExtension(options) {
11+
try {
12+
// We don't want to augment the window type in a library code, so we use type assertion instead
13+
// eslint-disable-next-line no-underscore-dangle, @typescript-eslint/no-explicit-any
14+
const reduxDevtools = typeof window === 'undefined' ? undefined : window.__REDUX_DEVTOOLS_EXTENSION__;
15+
if ((options === null || options === void 0 ? void 0 : options.remote) || !reduxDevtools) {
16+
return;
17+
}
18+
return reduxDevtools.connect(options);
19+
}
20+
catch (e) {
21+
console.error(ERROR_LABEL, e);
22+
}
23+
}
24+
/**
25+
* Registers an action that updated the current state of the storage
26+
*
27+
* @param type - name of the action
28+
* @param payload - data written to the storage
29+
* @param stateChanges - partial state that got updated after the changes
30+
*/
31+
registerAction(type, payload, stateChanges = {}) {
32+
try {
33+
if (!this.remoteDev) {
34+
return;
35+
}
36+
const newState = Object.assign(Object.assign({}, this.state), stateChanges);
37+
this.remoteDev.send({ type, payload }, newState);
38+
this.state = newState;
39+
}
40+
catch (e) {
41+
console.error(ERROR_LABEL, e);
42+
}
43+
}
44+
initState(initialState = {}) {
45+
try {
46+
if (!this.remoteDev) {
47+
return;
48+
}
49+
this.remoteDev.init(initialState);
50+
this.state = initialState;
51+
this.defaultState = initialState;
52+
}
53+
catch (e) {
54+
console.error(ERROR_LABEL, e);
55+
}
56+
}
57+
/**
58+
* This clears the internal state of the DevTools, preserving the keys included in `keysToPreserve`
59+
*/
60+
clearState(keysToPreserve = []) {
61+
const newState = Object.entries(this.state).reduce((obj, [key, value]) => {
62+
// eslint-disable-next-line no-param-reassign
63+
obj[key] = keysToPreserve.includes(key) ? value : this.defaultState[key];
64+
return obj;
65+
}, {});
66+
this.registerAction('CLEAR', undefined, newState);
67+
}
68+
}
69+
exports.default = new DevTools();

dist/Logger.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
type LogData = {
2+
message: string;
3+
level: 'alert' | 'info' | 'hmmm';
4+
};
5+
type LoggerCallback = (data: LogData) => void;
6+
/**
7+
* Register the logging callback
8+
*/
9+
declare function registerLogger(callback: LoggerCallback): void;
10+
/**
11+
* Send an alert message to the logger
12+
*/
13+
declare function logAlert(message: string): void;
14+
/**
15+
* Send an info message to the logger
16+
*/
17+
declare function logInfo(message: string): void;
18+
/**
19+
* Send an hmmm message to the logger
20+
*/
21+
declare function logHmmm(message: string): void;
22+
export { registerLogger, logInfo, logAlert, logHmmm };

dist/Logger.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.logHmmm = exports.logAlert = exports.logInfo = exports.registerLogger = void 0;
4+
// eslint-disable-next-line @typescript-eslint/no-empty-function
5+
let logger = () => { };
6+
/**
7+
* Register the logging callback
8+
*/
9+
function registerLogger(callback) {
10+
logger = callback;
11+
}
12+
exports.registerLogger = registerLogger;
13+
/**
14+
* Send an alert message to the logger
15+
*/
16+
function logAlert(message) {
17+
logger({ message: `[Onyx] ${message}`, level: 'alert' });
18+
}
19+
exports.logAlert = logAlert;
20+
/**
21+
* Send an info message to the logger
22+
*/
23+
function logInfo(message) {
24+
logger({ message: `[Onyx] ${message}`, level: 'info' });
25+
}
26+
exports.logInfo = logInfo;
27+
/**
28+
* Send an hmmm message to the logger
29+
*/
30+
function logHmmm(message) {
31+
logger({ message: `[Onyx] ${message}`, level: 'hmmm' });
32+
}
33+
exports.logHmmm = logHmmm;

dist/Onyx.d.ts

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import * as Logger from './Logger';
2+
import type { CollectionKeyBase, ConnectOptions, InitOptions, Mapping, OnyxKey, OnyxMergeCollectionInput, OnyxMergeInput, OnyxMultiSetInput, OnyxSetInput, OnyxUpdate } from './types';
3+
/** Initialize the store with actions and listening for storage events */
4+
declare function init({ keys, initialKeyStates, safeEvictionKeys, maxCachedKeysCount, shouldSyncMultipleInstances, debugSetState, }: InitOptions): void;
5+
/**
6+
* Subscribes a react component's state directly to a store key
7+
*
8+
* @example
9+
* const connectionID = Onyx.connect({
10+
* key: ONYXKEYS.SESSION,
11+
* callback: onSessionChange,
12+
* });
13+
*
14+
* @param mapping the mapping information to connect Onyx to the components state
15+
* @param mapping.key ONYXKEY to subscribe to
16+
* @param [mapping.statePropertyName] the name of the property in the state to connect the data to
17+
* @param [mapping.withOnyxInstance] whose setState() method will be called with any changed data
18+
* This is used by React components to connect to Onyx
19+
* @param [mapping.callback] a method that will be called with changed data
20+
* This is used by any non-React code to connect to Onyx
21+
* @param [mapping.initWithStoredValues] If set to false, then no data will be prefilled into the
22+
* component
23+
* @param [mapping.waitForCollectionCallback] If set to true, it will return the entire collection to the callback as a single object
24+
* @param [mapping.selector] THIS PARAM IS ONLY USED WITH withOnyx(). If included, this will be used to subscribe to a subset of an Onyx key's data.
25+
* The sourceData and withOnyx state are passed to the selector and should return the simplified data. Using this setting on `withOnyx` can have very positive
26+
* performance benefits because the component will only re-render when the subset of data changes. Otherwise, any change of data on any property would normally
27+
* cause the component to re-render (and that can be expensive from a performance standpoint).
28+
* @param [mapping.initialValue] THIS PARAM IS ONLY USED WITH withOnyx().
29+
* If included, this will be passed to the component so that something can be rendered while data is being fetched from the DB.
30+
* Note that it will not cause the component to have the loading prop set to true.
31+
* @returns an ID to use when calling disconnect
32+
*/
33+
declare function connect<TKey extends OnyxKey>(connectOptions: ConnectOptions<TKey>): number;
34+
/**
35+
* Remove the listener for a react component
36+
* @example
37+
* Onyx.disconnect(connectionID);
38+
*
39+
* @param connectionID unique id returned by call to Onyx.connect()
40+
*/
41+
declare function disconnect(connectionID: number, keyToRemoveFromEvictionBlocklist?: OnyxKey): void;
42+
/**
43+
* Write a value to our store with the given key
44+
*
45+
* @param key ONYXKEY to set
46+
* @param value value to store
47+
*/
48+
declare function set<TKey extends OnyxKey>(key: TKey, value: OnyxSetInput<TKey>): Promise<void>;
49+
/**
50+
* Sets multiple keys and values
51+
*
52+
* @example Onyx.multiSet({'key1': 'a', 'key2': 'b'});
53+
*
54+
* @param data object keyed by ONYXKEYS and the values to set
55+
*/
56+
declare function multiSet(data: OnyxMultiSetInput): Promise<void>;
57+
/**
58+
* Merge a new value into an existing value at a key.
59+
*
60+
* The types of values that can be merged are `Object` and `Array`. To set another type of value use `Onyx.set()`.
61+
* Values of type `Object` get merged with the old value, whilst for `Array`'s we simply replace the current value with the new one.
62+
*
63+
* Calls to `Onyx.merge()` are batched so that any calls performed in a single tick will stack in a queue and get
64+
* applied in the order they were called. Note: `Onyx.set()` calls do not work this way so use caution when mixing
65+
* `Onyx.merge()` and `Onyx.set()`.
66+
*
67+
* @example
68+
* Onyx.merge(ONYXKEYS.EMPLOYEE_LIST, ['Joe']); // -> ['Joe']
69+
* Onyx.merge(ONYXKEYS.EMPLOYEE_LIST, ['Jack']); // -> ['Joe', 'Jack']
70+
* Onyx.merge(ONYXKEYS.POLICY, {id: 1}); // -> {id: 1}
71+
* Onyx.merge(ONYXKEYS.POLICY, {name: 'My Workspace'}); // -> {id: 1, name: 'My Workspace'}
72+
*/
73+
declare function merge<TKey extends OnyxKey>(key: TKey, changes: OnyxMergeInput<TKey>): Promise<void>;
74+
/**
75+
* Merges a collection based on their keys
76+
*
77+
* @example
78+
*
79+
* Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, {
80+
* [`${ONYXKEYS.COLLECTION.REPORT}1`]: report1,
81+
* [`${ONYXKEYS.COLLECTION.REPORT}2`]: report2,
82+
* });
83+
*
84+
* @param collectionKey e.g. `ONYXKEYS.COLLECTION.REPORT`
85+
* @param collection Object collection keyed by individual collection member keys and values
86+
*/
87+
declare function mergeCollection<TKey extends CollectionKeyBase, TMap>(collectionKey: TKey, collection: OnyxMergeCollectionInput<TKey, TMap>): Promise<void>;
88+
/**
89+
* Clear out all the data in the store
90+
*
91+
* Note that calling Onyx.clear() and then Onyx.set() on a key with a default
92+
* key state may store an unexpected value in Storage.
93+
*
94+
* E.g.
95+
* Onyx.clear();
96+
* Onyx.set(ONYXKEYS.DEFAULT_KEY, 'default');
97+
* Storage.getItem(ONYXKEYS.DEFAULT_KEY)
98+
* .then((storedValue) => console.log(storedValue));
99+
* null is logged instead of the expected 'default'
100+
*
101+
* Onyx.set() might call Storage.setItem() before Onyx.clear() calls
102+
* Storage.setItem(). Use Onyx.merge() instead if possible. Onyx.merge() calls
103+
* Onyx.get(key) before calling Storage.setItem() via Onyx.set().
104+
* Storage.setItem() from Onyx.clear() will have already finished and the merged
105+
* value will be saved to storage after the default value.
106+
*
107+
* @param keysToPreserve is a list of ONYXKEYS that should not be cleared with the rest of the data
108+
*/
109+
declare function clear(keysToPreserve?: OnyxKey[]): Promise<void>;
110+
/**
111+
* Insert API responses and lifecycle data into Onyx
112+
*
113+
* @param data An array of objects with update expressions
114+
* @returns resolves when all operations are complete
115+
*/
116+
declare function update(data: OnyxUpdate[]): Promise<void>;
117+
declare const Onyx: {
118+
readonly METHOD: {
119+
readonly SET: "set";
120+
readonly MERGE: "merge";
121+
readonly MERGE_COLLECTION: "mergecollection";
122+
readonly MULTI_SET: "multiset";
123+
readonly CLEAR: "clear";
124+
};
125+
readonly connect: typeof connect;
126+
readonly disconnect: typeof disconnect;
127+
readonly set: typeof set;
128+
readonly multiSet: typeof multiSet;
129+
readonly merge: typeof merge;
130+
readonly mergeCollection: typeof mergeCollection;
131+
readonly update: typeof update;
132+
readonly clear: typeof clear;
133+
readonly init: typeof init;
134+
readonly registerLogger: typeof Logger.registerLogger;
135+
};
136+
export default Onyx;
137+
export type { OnyxUpdate, Mapping, ConnectOptions };

0 commit comments

Comments
 (0)