Skip to content

Commit d586f19

Browse files
authored
feat(redux-devtools-serialize): convert to TypeScript (#621)
* feature(redux-devtools-serialize): convert to TypeScript * unused
1 parent 0663b7c commit d586f19

File tree

27 files changed

+538
-322
lines changed

27 files changed

+538
-322
lines changed

packages/react-base16-styling/.eslintrc.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ module.exports = {
22
extends: '../../.eslintrc',
33
overrides: [
44
{
5-
files: ['*.ts', '*.tsx'],
5+
files: ['*.ts'],
66
extends: '../../eslintrc.ts.base.json',
77
parserOptions: {
88
tsconfigRootDir: __dirname,
99
project: ['./tsconfig.json'],
1010
},
1111
},
1212
{
13-
files: ['test/*.ts', 'test/*.tsx'],
13+
files: ['test/*.ts'],
1414
extends: '../../eslintrc.ts.jest.base.json',
1515
parserOptions: {
1616
tsconfigRootDir: __dirname,

packages/redux-devtools-dock-monitor/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"lint:fix": "eslint . --ext .ts,.tsx --fix",
3737
"type-check": "tsc --noEmit",
3838
"type-check:watch": "npm run type-check -- --watch",
39-
"preversion": "npm run type-check && npm run lint && npm run test",
39+
"preversion": "npm run type-check && npm run lint",
4040
"prepublishOnly": "npm run clean && npm run build"
4141
},
4242
"dependencies": {

packages/redux-devtools-instrument/.eslintrc.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ module.exports = {
22
extends: '../../.eslintrc',
33
overrides: [
44
{
5-
files: ['*.ts', '*.tsx'],
5+
files: ['*.ts'],
66
extends: '../../eslintrc.ts.base.json',
77
parserOptions: {
88
tsconfigRootDir: __dirname,
99
project: ['./tsconfig.json'],
1010
},
1111
},
1212
{
13-
files: ['test/*.ts', 'test/*.tsx'],
13+
files: ['test/*.ts'],
1414
extends: '../../eslintrc.ts.jest.base.json',
1515
parserOptions: {
1616
tsconfigRootDir: __dirname,

packages/redux-devtools-instrument/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"build:js": "babel src --out-dir lib --extensions \".ts\" --source-maps inline",
3333
"clean": "rimraf lib",
3434
"test": "jest",
35-
"lint": "eslint . --ext .ts,.tsx",
36-
"lint:fix": "eslint . --ext .ts,.tsx --fix",
35+
"lint": "eslint . --ext .ts",
36+
"lint:fix": "eslint . --ext .ts --fix",
3737
"type-check": "tsc --noEmit",
3838
"type-check:watch": "npm run type-check -- --watch",
3939
"preversion": "npm run type-check && npm run lint && npm run test",

packages/redux-devtools-log-monitor/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"lint:fix": "eslint . --ext .ts,.tsx --fix",
3737
"type-check": "tsc --noEmit",
3838
"type-check:watch": "npm run type-check -- --watch",
39-
"preversion": "npm run type-check && npm run lint && npm run test",
39+
"preversion": "npm run type-check && npm run lint",
4040
"prepublishOnly": "npm run clean && npm run build"
4141
},
4242
"dependencies": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["@babel/preset-env", "@babel/preset-typescript"],
3+
"plugins": ["@babel/plugin-proposal-class-properties"]
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lib
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
extends: '../../.eslintrc',
3+
overrides: [
4+
{
5+
files: ['*.ts'],
6+
extends: '../../eslintrc.ts.base.json',
7+
parserOptions: {
8+
tsconfigRootDir: __dirname,
9+
project: ['./tsconfig.json'],
10+
},
11+
},
12+
{
13+
files: ['test/*.ts'],
14+
extends: '../../eslintrc.ts.jest.base.json',
15+
parserOptions: {
16+
tsconfigRootDir: __dirname,
17+
project: ['./test/tsconfig.json'],
18+
},
19+
},
20+
],
21+
};

packages/redux-devtools-serialize/helpers/index.js

-32
This file was deleted.

packages/redux-devtools-serialize/immutable/index.js

-23
This file was deleted.

packages/redux-devtools-serialize/immutable/serialize.js

-87
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
};

packages/redux-devtools-serialize/package.json

+27-14
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,42 @@
22
"name": "redux-devtools-serialize",
33
"version": "0.1.9",
44
"description": "Serialize unserializable data and parse it back.",
5-
"main": "index.js",
6-
"scripts": {
7-
"test": "jest --no-cache",
8-
"prepublish": "npm run test"
9-
},
10-
"repository": {
11-
"type": "git",
12-
"url": "https://github.com/reduxjs/redux-devtools.git"
13-
},
145
"keywords": [
156
"redux",
167
"devtools"
178
],
18-
"author": "Mihail Diordiev <zalmoxisus@gmail.com> (https://github.com/zalmoxisus)",
19-
"license": "MIT",
9+
"homepage": "https://github.com/reduxjs/redux-devtools/tree/master/packages/redux-devtools-serialize",
2010
"bugs": {
2111
"url": "https://github.com/reduxjs/redux-devtools/issues"
2212
},
23-
"homepage": "https://github.com/reduxjs/redux-devtools",
24-
"devDependencies": {
25-
"immutable": "^4.0.0-rc.12"
13+
"license": "MIT",
14+
"author": "Mihail Diordiev <zalmoxisus@gmail.com> (https://github.com/zalmoxisus)",
15+
"main": "lib/index.js",
16+
"types": "lib/index.d.ts",
17+
"repository": {
18+
"type": "git",
19+
"url": "https://github.com/reduxjs/redux-devtools.git"
20+
},
21+
"scripts": {
22+
"build": "npm run build:types && npm run build:js",
23+
"build:types": "tsc --emitDeclarationOnly",
24+
"build:js": "babel src --out-dir lib --extensions \".ts\" --source-maps inline",
25+
"clean": "rimraf lib",
26+
"test": "jest",
27+
"lint": "eslint . --ext .ts",
28+
"lint:fix": "eslint . --ext .ts --fix",
29+
"type-check": "tsc --noEmit",
30+
"type-check:watch": "npm run type-check -- --watch",
31+
"preversion": "npm run type-check && npm run lint && npm run test",
32+
"prepublishOnly": "npm run clean && npm run build"
2633
},
2734
"dependencies": {
2835
"jsan": "^3.1.13"
36+
},
37+
"devDependencies": {
38+
"immutable": "^4.0.0-rc.12"
39+
},
40+
"peerDependencies": {
41+
"immutable": "^4.0.0-rc.12"
2942
}
3043
}

packages/redux-devtools-serialize/constants/options.js renamed to packages/redux-devtools-serialize/src/constants/options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// jsan stringify options
22

3-
module.exports = {
3+
export default {
44
refs: false, // references can't be resolved on the original Immutable structure
55
date: true,
66
function: true,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
export interface SerializedData {
2+
data: unknown;
3+
__serializedType__: string;
4+
__serializedRef__?: number;
5+
}
6+
7+
export function mark(data: unknown, type: string): SerializedData;
8+
export function mark<K extends string>(
9+
data: { [key in K]: () => unknown },
10+
type: string,
11+
transformMethod?: K | false
12+
): SerializedData;
13+
export function mark<K extends string>(
14+
data: any,
15+
type: string,
16+
transformMethod?: 'toString' | false
17+
): SerializedData;
18+
export function mark<K extends string>(
19+
data: { [key in K]: () => unknown } | unknown,
20+
type: string,
21+
transformMethod?: K | false
22+
): SerializedData {
23+
return {
24+
data: transformMethod
25+
? (data as { [key in K]: () => unknown })[transformMethod]()
26+
: data,
27+
__serializedType__: type,
28+
};
29+
}
30+
31+
export function extract(data: unknown, type: string): SerializedData {
32+
return {
33+
data: Object.assign({}, data),
34+
__serializedType__: type,
35+
};
36+
}
37+
38+
export function refer<K extends string>(
39+
data: { [key in K]: () => unknown },
40+
type: string,
41+
transformMethod: K | false,
42+
refs?: (new (data: any) => unknown)[] | null
43+
): SerializedData {
44+
const r = mark(data, type, transformMethod);
45+
if (!refs) return r;
46+
for (let i = 0; i < refs.length; i++) {
47+
const ref = refs[i];
48+
if (typeof ref === 'function' && data instanceof ref) {
49+
r.__serializedRef__ = i;
50+
return r;
51+
}
52+
}
53+
return r;
54+
}

0 commit comments

Comments
 (0)