Skip to content

Commit

Permalink
feat(redux-devtools-serialize): convert to TypeScript (#621)
Browse files Browse the repository at this point in the history
* feature(redux-devtools-serialize): convert to TypeScript

* unused
  • Loading branch information
Methuselah96 committed Aug 29, 2020
1 parent 0663b7c commit d586f19
Show file tree
Hide file tree
Showing 27 changed files with 538 additions and 322 deletions.
4 changes: 2 additions & 2 deletions packages/react-base16-styling/.eslintrc.js
Expand Up @@ -2,15 +2,15 @@ module.exports = {
extends: '../../.eslintrc',
overrides: [
{
files: ['*.ts', '*.tsx'],
files: ['*.ts'],
extends: '../../eslintrc.ts.base.json',
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
},
{
files: ['test/*.ts', 'test/*.tsx'],
files: ['test/*.ts'],
extends: '../../eslintrc.ts.jest.base.json',
parserOptions: {
tsconfigRootDir: __dirname,
Expand Down
2 changes: 1 addition & 1 deletion packages/redux-devtools-dock-monitor/package.json
Expand Up @@ -36,7 +36,7 @@
"lint:fix": "eslint . --ext .ts,.tsx --fix",
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch",
"preversion": "npm run type-check && npm run lint && npm run test",
"preversion": "npm run type-check && npm run lint",
"prepublishOnly": "npm run clean && npm run build"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/redux-devtools-instrument/.eslintrc.js
Expand Up @@ -2,15 +2,15 @@ module.exports = {
extends: '../../.eslintrc',
overrides: [
{
files: ['*.ts', '*.tsx'],
files: ['*.ts'],
extends: '../../eslintrc.ts.base.json',
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
},
{
files: ['test/*.ts', 'test/*.tsx'],
files: ['test/*.ts'],
extends: '../../eslintrc.ts.jest.base.json',
parserOptions: {
tsconfigRootDir: __dirname,
Expand Down
4 changes: 2 additions & 2 deletions packages/redux-devtools-instrument/package.json
Expand Up @@ -32,8 +32,8 @@
"build:js": "babel src --out-dir lib --extensions \".ts\" --source-maps inline",
"clean": "rimraf lib",
"test": "jest",
"lint": "eslint . --ext .ts,.tsx",
"lint:fix": "eslint . --ext .ts,.tsx --fix",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch",
"preversion": "npm run type-check && npm run lint && npm run test",
Expand Down
2 changes: 1 addition & 1 deletion packages/redux-devtools-log-monitor/package.json
Expand Up @@ -36,7 +36,7 @@
"lint:fix": "eslint . --ext .ts,.tsx --fix",
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch",
"preversion": "npm run type-check && npm run lint && npm run test",
"preversion": "npm run type-check && npm run lint",
"prepublishOnly": "npm run clean && npm run build"
},
"dependencies": {
Expand Down
4 changes: 4 additions & 0 deletions packages/redux-devtools-serialize/.babelrc
@@ -0,0 +1,4 @@
{
"presets": ["@babel/preset-env", "@babel/preset-typescript"],
"plugins": ["@babel/plugin-proposal-class-properties"]
}
1 change: 1 addition & 0 deletions packages/redux-devtools-serialize/.eslintignore
@@ -0,0 +1 @@
lib
21 changes: 21 additions & 0 deletions packages/redux-devtools-serialize/.eslintrc.js
@@ -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'],
},
},
],
};
32 changes: 0 additions & 32 deletions packages/redux-devtools-serialize/helpers/index.js

This file was deleted.

23 changes: 0 additions & 23 deletions packages/redux-devtools-serialize/immutable/index.js

This file was deleted.

87 changes: 0 additions & 87 deletions packages/redux-devtools-serialize/immutable/serialize.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/redux-devtools-serialize/jest.config.js
@@ -0,0 +1,3 @@
module.exports = {
preset: 'ts-jest',
};
41 changes: 27 additions & 14 deletions packages/redux-devtools-serialize/package.json
Expand Up @@ -2,29 +2,42 @@
"name": "redux-devtools-serialize",
"version": "0.1.9",
"description": "Serialize unserializable data and parse it back.",
"main": "index.js",
"scripts": {
"test": "jest --no-cache",
"prepublish": "npm run test"
},
"repository": {
"type": "git",
"url": "https://github.com/reduxjs/redux-devtools.git"
},
"keywords": [
"redux",
"devtools"
],
"author": "Mihail Diordiev <zalmoxisus@gmail.com> (https://github.com/zalmoxisus)",
"license": "MIT",
"homepage": "https://github.com/reduxjs/redux-devtools/tree/master/packages/redux-devtools-serialize",
"bugs": {
"url": "https://github.com/reduxjs/redux-devtools/issues"
},
"homepage": "https://github.com/reduxjs/redux-devtools",
"devDependencies": {
"immutable": "^4.0.0-rc.12"
"license": "MIT",
"author": "Mihail Diordiev <zalmoxisus@gmail.com> (https://github.com/zalmoxisus)",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/reduxjs/redux-devtools.git"
},
"scripts": {
"build": "npm run build:types && npm run build:js",
"build:types": "tsc --emitDeclarationOnly",
"build:js": "babel src --out-dir lib --extensions \".ts\" --source-maps inline",
"clean": "rimraf lib",
"test": "jest",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch",
"preversion": "npm run type-check && npm run lint && npm run test",
"prepublishOnly": "npm run clean && npm run build"
},
"dependencies": {
"jsan": "^3.1.13"
},
"devDependencies": {
"immutable": "^4.0.0-rc.12"
},
"peerDependencies": {
"immutable": "^4.0.0-rc.12"
}
}
@@ -1,6 +1,6 @@
// jsan stringify options

module.exports = {
export default {
refs: false, // references can't be resolved on the original Immutable structure
date: true,
function: true,
Expand Down
54 changes: 54 additions & 0 deletions packages/redux-devtools-serialize/src/helpers/index.ts
@@ -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;
}

0 comments on commit d586f19

Please sign in to comment.