Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(redux-devtools-serialize): convert to TypeScript (#621)
* feature(redux-devtools-serialize): convert to TypeScript * unused
- Loading branch information
1 parent
0663b7c
commit d586f19
Showing
27 changed files
with
538 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"presets": ["@babel/preset-env", "@babel/preset-typescript"], | ||
"plugins": ["@babel/plugin-proposal-class-properties"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module.exports = { | ||
extends: '../../.eslintrc', | ||
overrides: [ | ||
{ | ||
files: ['*.ts'], | ||
extends: '../../eslintrc.ts.base.json', | ||
parserOptions: { | ||
tsconfigRootDir: __dirname, | ||
project: ['./tsconfig.json'], | ||
}, | ||
}, | ||
{ | ||
files: ['test/*.ts'], | ||
extends: '../../eslintrc.ts.jest.base.json', | ||
parserOptions: { | ||
tsconfigRootDir: __dirname, | ||
project: ['./test/tsconfig.json'], | ||
}, | ||
}, | ||
], | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...x-devtools-serialize/constants/options.js → ...vtools-serialize/src/constants/options.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
export interface SerializedData { | ||
data: unknown; | ||
__serializedType__: string; | ||
__serializedRef__?: number; | ||
} | ||
|
||
export function mark(data: unknown, type: string): SerializedData; | ||
export function mark<K extends string>( | ||
data: { [key in K]: () => unknown }, | ||
type: string, | ||
transformMethod?: K | false | ||
): SerializedData; | ||
export function mark<K extends string>( | ||
data: any, | ||
type: string, | ||
transformMethod?: 'toString' | false | ||
): SerializedData; | ||
export function mark<K extends string>( | ||
data: { [key in K]: () => unknown } | unknown, | ||
type: string, | ||
transformMethod?: K | false | ||
): SerializedData { | ||
return { | ||
data: transformMethod | ||
? (data as { [key in K]: () => unknown })[transformMethod]() | ||
: data, | ||
__serializedType__: type, | ||
}; | ||
} | ||
|
||
export function extract(data: unknown, type: string): SerializedData { | ||
return { | ||
data: Object.assign({}, data), | ||
__serializedType__: type, | ||
}; | ||
} | ||
|
||
export function refer<K extends string>( | ||
data: { [key in K]: () => unknown }, | ||
type: string, | ||
transformMethod: K | false, | ||
refs?: (new (data: any) => unknown)[] | null | ||
): SerializedData { | ||
const r = mark(data, type, transformMethod); | ||
if (!refs) return r; | ||
for (let i = 0; i < refs.length; i++) { | ||
const ref = refs[i]; | ||
if (typeof ref === 'function' && data instanceof ref) { | ||
r.__serializedRef__ = i; | ||
return r; | ||
} | ||
} | ||
return r; | ||
} |
Oops, something went wrong.