Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HOLD: Migrate heart of react-native-onyx, Onyx.js to TS! #481

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e7fa792
Initial migration of Onyx.js
blazejkustra Feb 28, 2024
c8aec7b
Continue migrating
blazejkustra Feb 28, 2024
0950f52
Rename types.d.ts to types.ts
blazejkustra Feb 28, 2024
5ace7b0
Clear a lot of errors
blazejkustra Feb 28, 2024
a01ffd2
Fix errors related to tests
blazejkustra Feb 28, 2024
2a9aa58
Remove unneccessary metrics tests
blazejkustra Feb 28, 2024
d1e116e
Merge branch 'ts/remaining-files' into ts/Onyx
blazejkustra Feb 29, 2024
c191fd9
Merge branch 'main' into ts/Onyx
blazejkustra Mar 4, 2024
a7ed2b7
Adjust PerformanceUtils import
blazejkustra Mar 4, 2024
6236ca0
Migrate index.js
blazejkustra Mar 4, 2024
6a9c50f
Migrate DevTools.js
blazejkustra Mar 4, 2024
db462ca
Export types from Onyx.js
blazejkustra Mar 4, 2024
1741bab
Fix linter errors
blazejkustra Mar 4, 2024
d1836b4
Continue migrating Onyx
blazejkustra Mar 4, 2024
73fc038
Remove MDTable
blazejkustra Mar 5, 2024
2b86307
Clear all errors
blazejkustra Mar 5, 2024
ac07d88
Fix error with clear()
blazejkustra Mar 5, 2024
d2fe5c7
Fix error with OnyxCache
blazejkustra Mar 5, 2024
f717d46
Make a change that is already on main
blazejkustra Mar 5, 2024
556f183
Adjust getCollectionDataAndSendAsObject
blazejkustra Mar 5, 2024
f003e69
Fix last failing test
blazejkustra Mar 5, 2024
f709737
Merge branch 'main' into ts/Onyx
blazejkustra Mar 5, 2024
437fdbc
Add back setMemoryOnlyKeys
blazejkustra Mar 5, 2024
9f5d72a
Add final assertion
blazejkustra Mar 5, 2024
d34a077
Fix connect types
blazejkustra Mar 5, 2024
78ec402
Fix ConnectOptions type
blazejkustra Mar 5, 2024
850805f
Merge branch 'main' into ts/Onyx
blazejkustra Mar 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
project: './tsconfig.json',
},
rules: {
'@typescript-eslint/prefer-for-of': 'off',
'rulesdir/prefer-underscore-method': 'off',
'react/jsx-props-no-spreading': 'off',
'react/require-default-props': 'off',
Expand Down
71 changes: 0 additions & 71 deletions lib/DevTools.js

This file was deleted.

104 changes: 104 additions & 0 deletions lib/DevTools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
type DevtoolsOptions = {
maxAge?: number;
name?: string;
postTimelineUpdate?: () => void;
preAction?: () => void;
logTrace?: boolean;
remote?: boolean;
};

type DevtoolsSubscriber = (message: {type: string; payload: unknown; state: string}) => void;

type DevtoolsConnection = {
send(data: Record<string, unknown>, state: Record<string, unknown>): void;
init(state: Record<string, unknown>): void;
unsubscribe(): void;
subscribe(cb: DevtoolsSubscriber): () => void;
};

const ERROR_LABEL = 'Onyx DevTools - Error: ';

type ReduxDevtools = {
connect(options?: DevtoolsOptions): DevtoolsConnection;
};

class DevTools {
private remoteDev?: DevtoolsConnection;

private state: Record<string, unknown>;

private defaultState: Record<string, unknown>;

constructor() {
this.remoteDev = this.connectViaExtension();
this.state = {};
this.defaultState = {};
}

connectViaExtension(options?: DevtoolsOptions): DevtoolsConnection | undefined {
try {
// We don't want to augment the window type in a library code, so we use type assertion instead
// eslint-disable-next-line no-underscore-dangle, @typescript-eslint/no-explicit-any
const reduxDevtools: ReduxDevtools = (window as any).__REDUX_DEVTOOLS_EXTENSION__;

if ((options && options.remote) || typeof window === 'undefined' || !reduxDevtools) {
return;
}
// eslint-disable-next-line no-underscore-dangle, @typescript-eslint/no-explicit-any
return reduxDevtools.connect(options);
} catch (e) {
console.error(ERROR_LABEL, e);
}
}

/**
* Registers an action that updated the current state of the storage
*
* @param type - name of the action
* @param payload - data written to the storage
* @param stateChanges - partial state that got updated after the changes
*/
registerAction(type: string, payload: unknown, stateChanges: Record<string, unknown> = {}) {
try {
if (!this.remoteDev) {
return;
}
const newState = {
...this.state,
...stateChanges,
};
this.remoteDev.send({type, payload}, newState);
this.state = newState;
} catch (e) {
console.error(ERROR_LABEL, e);
}
}

initState(initialState: Record<string, unknown> = {}) {
try {
if (!this.remoteDev) {
return;
}
this.remoteDev.init(initialState);
this.state = initialState;
this.defaultState = initialState;
} catch (e) {
console.error(ERROR_LABEL, e);
}
}

/**
* This clears the internal state of the DevTools, preserving the keys included in `keysToPreserve`
*/
public clearState(keysToPreserve: string[] = []): void {
const newState = Object.entries(this.state).reduce((obj: Record<string, unknown>, [key, value]) => {
// eslint-disable-next-line no-param-reassign
obj[key] = keysToPreserve.includes(key) ? value : this.defaultState[key];
return obj;
}, {});

this.registerAction('CLEAR', undefined, newState);
}
}

export default new DevTools();
66 changes: 0 additions & 66 deletions lib/MDTable.js

This file was deleted.

Loading
Loading