Skip to content

Commit

Permalink
TSDX
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Feb 13, 2020
1 parent ee1c977 commit 4c4fecc
Show file tree
Hide file tree
Showing 11 changed files with 2,776 additions and 2,974 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"plugins": [["@babel/plugin-proposal-optional-chaining"]]
"presets": [["@babel/preset-env", { "targets": { "ie": "11" } }]]
}
30 changes: 0 additions & 30 deletions bili.config.ts

This file was deleted.

49 changes: 9 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,17 @@
{
"name": "immer",
"version": "5.3.2",
"version": "6.0.0-alpha.2",
"description": "Create your next immutable state by mutating the current one",
"main": "dist/immer.js",
"module": "dist/immer.module.js",
"umd:main": "dist/immer.umd.js",
"unpkg": "dist/immer.umd.js",
"jsdelivr": "dist/immer.umd.js",
"jsnext:main": "dist/immer.module.js",
"react-native": "dist/immer.module.js",
"module": "dist/immer.esm.js",
"umd:main": "dist/immer.umd.production.min.js",
"unpkg": "dist/immer.umd.production.min.js",
"jsdelivr": "dist/immer.umd.production.min.js",
"jsnext:main": "dist/immer.esm.js",
"react-native": "dist/immer.esm.js",
"source": "src/immer.ts",
"types": "./dist/immer.d.ts",
"sideEffects": false,
"exports": {
".": {
"browser": "./dist/immer.module.js",
"umd": "./dist/immer.umd.js",
"import": "./dist/immer.module.js",
"require": "./didst/immer.js"
},
"es5": {
"browser": "./dist/es5.module.js",
"umd": "./dist/es5.umd.js",
"import": "./dist/es5.module.js",
"require": "./didst/es5.js"
},
"mapset": {
"browser": "./dist/mapset.module.js",
"umd": "./dist/mapset.umd.js",
"import": "./dist/mapset.module.js",
"require": "./didst/mapset.js"
},
"patches": {
"browser": "./dist/patches.module.js",
"umd": "./dist/patches.umd.js",
"import": "./dist/patches.module.js",
"require": "./didst/patches.js"
}
},
"scripts": {
"test": "jest && yarn-or-npm test:build && yarn-or-npm test:flow",
"test:perf": "NODE_ENV=production yarn-or-npm build && cd __performance_tests__ && babel-node add-data.js && babel-node todo.js && babel-node incremental.js",
Expand All @@ -46,9 +20,7 @@
"watch": "jest --watch",
"coverage": "jest --coverage",
"coveralls": "jest --coverage && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf ./coverage",
"build": "rimraf dist/ && yarn build:immer && yarn build:es5 && yarn build:patches && yarn build:mapset",
"build:immer": "microbundle build --raw",
"build:es5": "microbundle build --raw --entry src/plugins/es5.ts --output dist",
"build": "rimraf dist/ && tsdx build --name immer --format cjs,esm,umd",
"typed": "cpx 'src/immer.js.flow' dist -v",
"publish-docs": "cd website && GIT_USER=mweststrate USE_SSH=true yarn run publish-gh-pages",
"start": "cd website && yarn start"
Expand Down Expand Up @@ -82,26 +54,23 @@
"src"
],
"devDependencies": {
"@babel/plugin-proposal-optional-chaining": "^7.8.3",
"coveralls": "^3.0.0",
"cpx": "^1.5.0",
"cross-env": "^5.1.3",
"deep-freeze": "^0.0.1",
"flow-bin": "^0.68.0",
"husky": "^1.2.0",
"immutable": "^3.8.2",
"jest": "^25.1.0",
"lodash": "^4.17.4",
"lodash.clonedeep": "^4.5.0",
"microbundle": "^0.12.0-next.8",
"prettier": "1.19.1",
"pretty-quick": "^1.8.0",
"redux": "^4.0.5",
"rimraf": "^2.6.2",
"seamless-immutable": "^7.1.3",
"semantic-release": "^17.0.2",
"spec.ts": "^1.1.0",
"ts-jest": "^25.2.0",
"tsdx": "^0.12.3",
"typescript": "^3.7.3"
},
"jest": {
Expand Down
7 changes: 5 additions & 2 deletions src/immer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export {
isDraft,
isDraftable,
NOTHING as nothing,
DRAFTABLE as immerable,
__loadPlugin
DRAFTABLE as immerable
} from "./internal"

const immer = new Immer()
Expand Down Expand Up @@ -109,3 +108,7 @@ export function castImmutable<T>(value: T): Immutable<T> {
}

export {Immer}

export {enableES5} from "./plugins/es5"
export {enablePatches} from "./plugins/patches"
export {enableMapSet} from "./plugins/mapset"
70 changes: 6 additions & 64 deletions src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,8 @@ import {
ImmerBaseState,
AnyArray,
AnyMap,
DRAFT_STATE,
AnySet,
get,
each,
has,
die,
getArchtype,
ProxyType,
Archtype,
isSet,
isMap,
isDraft,
isDraftable,
isEnumerable,
shallowCopy,
latest,
createHiddenProperty,
assertUnrevoked,
is,
createProxy,
iteratorSymbol
ProxyType
} from "./internal"

/** Plugin utilities */
Expand All @@ -49,8 +30,6 @@ const plugins: {

type Plugins = typeof plugins

export type Utilities = ReturnType<typeof buildUtilities>

export function getPlugin<K extends keyof Plugins>(
pluginKey: K
): Exclude<Plugins[K], undefined> {
Expand All @@ -64,42 +43,11 @@ export function getPlugin<K extends keyof Plugins>(
return plugin
}

function buildUtilities() {
return {
get,
each,
has,
die,
getArchtype,
ProxyType,
Archtype,
isSet,
isMap,
isDraft,
isDraftable,
isEnumerable,
shallowCopy,
latest,
createHiddenProperty,
ImmerScope,
DRAFT_STATE,
assertUnrevoked,
is,
iteratorSymbol,
createProxy
} as const
}

let utilities: Utilities | undefined = undefined

export function __loadPlugin<K extends keyof Plugins>(
export function loadPlugin<K extends keyof Plugins>(
pluginKey: K,
getImplementation: (core: any /* TODO: Utilities */) => Plugins[K]
implementation: Plugins[K]
): void {
if (!utilities) {
utilities = buildUtilities()
}
plugins[pluginKey] = getImplementation(utilities)
plugins[pluginKey] = implementation
}

/** ES5 Plugin */
Expand Down Expand Up @@ -164,17 +112,11 @@ export interface SetState extends ImmerBaseState {
draft: Drafted<AnySet, SetState>
}

export function proxyMap<T extends AnyMap>(
target: T,
parent?: ImmerState
): T & {[DRAFT_STATE]: MapState} {
export function proxyMap<T extends AnyMap>(target: T, parent?: ImmerState): T {
return getPlugin("mapset").proxyMap(target, parent)
}

export function proxySet<T extends AnySet>(
target: T,
parent?: ImmerState
): T & {[DRAFT_STATE]: SetState} {
export function proxySet<T extends AnySet>(target: T, parent?: ImmerState): T {
return getPlugin("mapset").proxySet(target, parent)
}

Expand Down
Loading

0 comments on commit 4c4fecc

Please sign in to comment.