Merge branch 'master' into feature/es5
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Michel Weststrate · committed by Michel Weststrate · parents 32710af, 4d4b1c9 · Browse files · 8 files·+28 added−24 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+28 added−24 removed
- tests:+17 added−17 removed
- other:+11 added−7 removed
Provenance
- Commit
9b193bc- Tree
1f952d0- Author
Michel Weststrate <mweststrate@gmail.com>- Committer
Michel Weststrate <mweststrate@gmail.com>- Parent 1
32710af- Parent 2
4d4b1c9
8 files changed+28 added−24 removed
modified:__tests__/base.js+9 added-9 removed
147 unmodified lines148 anArray: [3, 2, {c: 3}, 1],149 aProp: "hi",150 messy: {151 nested: {152- yummie: true,152+ yummie: true153 },154- coffee: false,155- },154+ coffee: false155+ }156 })157 expect(nextState.messy.nested).toBe(baseState.anObject.nested)158 })159 11 unmodified lines171 anArray: [3, 2, {c: 3}, 1],172 aProp: "hello",173 messy: {174 nested: {175- yummie: true,175+ yummie: true176 },177- coffee: true,178- },177+ coffee: true178+ }179 })180 expect(nextState.messy.nested).toBe(baseState.anObject.nested)181 })182 54 unmodified lines237 anArray: [3, 2, {c: 3}, 1],238 aProp: "hi",239 anObject: {240 nested: {241- yummie: true,241+ yummie: true242 },243- coffee: false,244- },243+ coffee: false244+ }245 }246 }247 })modified:__tests__/frozen.js+1 added-1 removed
2 unmodified lines34567789101138 unmodified lines2 unmodified lines
describe("auto freeze", () => { const baseState = { object: {a: 1}, array: [1, 2], array: [1, 2] }
it("should freeze objects after modifications", () => { expect(Object.isFrozen(baseState.object)).toBe(false) // initially not frozen38 unmodified linesmodified:__tests__/performance.js+4 added-4 removed
13 unmodified lines141516171818192021229 unmodified lines3233343536363738394014 unmodified lines5556575859596061616263646527 unmodified lines13 unmodified lines for (let i = 0; i < MAX; i++) { baseState.push({ todo: "todo_" + i, done: false, someThingCompletelyIrrelevant: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], someThingCompletelyIrrelevant: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] }) }
// Produce the frozen bazeState9 unmodified lines // generate immutalbeJS base state const todoRecord = Record({ todo: "", done: false, someThingCompletelyIrrelevant: [], someThingCompletelyIrrelevant: [] }) immutableJsBaseState = List(baseState.map(todo => todoRecord(todo)))
// The benchmarks14 unmodified lines test("handcrafted reducer", () => { const nextState = [ ...baseState.slice(0, MAX * MODIFY_FACTOR).map(todo => ({ ...todo, done: true, done: true })), ...baseState.slice(MAX * MODIFY_FACTOR), ...baseState.slice(MAX * MODIFY_FACTOR) ] })
test("immutableJS", () => {27 unmodified linesmodified:__tests__/readme.js+3 added-3 removed
4 unmodified lines567899101112131413141516171818 unmodified lines4 unmodified lines it("works", () => { const baseState = [ { todo: "Learn typescript", done: true, done: true }, { todo: "Try immer", done: false, }, done: false } ]
const nextState = immer(baseState, draft => { draft.push({todo: "Tweet about it"})18 unmodified linesmodified:.prettierrc+1 added-1 removed
4 unmodified lines5 "requirePragma": false,6 "semi": false,7 "singleQuote": false,8 "tabWidth": 4,9- "trailingComma": "all",9+ "trailingComma": "none",10 "useTabs": false,11 "overrides": [12 {13 "files": "*.json",6 unmodified linesmodified:changelog.md+5 added-1 removed
1 # Changelog2 3+### 0.1.2 (2-1-2018)4+5+* Fixed issue where trailing commas could break consumers. Fixes [#21](https://github.com/mweststrate/immer/pull/21).6+7 ### 0.1.1 (2-1-2018)8 5-* Fixed issue where TypeScript typings were not correctly exposed. Fixes [#18](https://github.com/mweststrate/immer/pull/18).9+* Fixed issue where TypeScript typings were not correctly exposed. Fixes [#18](https://github.com/mweststrate/immer/issue/18).10 11 ### 0.1.0 (1-1-2018)12 13 * Fixed `immer` function export, it is now properly exposed as the `default` export. So `import immer from "immer"`. See [#15](https://github.com/mweststrate/immer/pull/15)9 unmodified linesmodified:immer.js+4 added-4 removed
59 unmodified lines60 deleteProperty(target, property) {61 const copy = getOrCreateCopy(target)62 delete copy[property]63 return true64- },64+ }65 }66 67 // creates a copy for a base object if there ain't one68 function getOrCreateCopy(base) {31 unmodified lines100 : Object.assign({}, base)101 Object.defineProperty(proxyTarget, CLONE_TARGET, {102 enumerable: false,103 value: base,104- configurable: true,104+ configurable: true105 })106 } else {107 proxyTarget = base108 }57 unmodified lines166 const maybeVoidReturn = thunk(rootClone)167 //values either than undefined will trigger warning;168 !Object.is(maybeVoidReturn, undefined) &&169 console.warn(170- `Immer callback expects no return value. However ${typeof maybeVoidReturn} was returned`,170+ `Immer callback expects no return value. However ${typeof maybeVoidReturn} was returned`171 )172 // console.log(`proxies: ${revocableProxies.size}, copies: ${copies.size}`)173 // revoke all proxies174 revoke(revocableProxies)41 unmodified lines216 autoFreeze = enableAutoFreeze217 }218 219 Object.defineProperty(exports, "__esModule", {220- value: true,220+ value: true221 })222 module.exports.default = immer223 module.exports.setAutoFreeze = setAutoFreezemodified:package.json+1 added-1 removed
1 {2 "name": "immer",3- "version": "0.1.0",3+ "version": "0.1.2",4 "description": "Create your next immutable state by mutating the current one",5 "main": "immer-es5.js",6 "types": "./index.d.ts",7 "scripts": {44 unmodified lines