Skip to content
Myr

curry.js

This file

Path

__tests__/curry.js

67 lines · 2.3 KiB · JavaScript

Last changed by

Merge branch 'patches'Michel Weststratebefore adoption2513fb8

History of this file

Take it

Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e

line 1why, one step back
1"use strict"

Renamed `index.js` -> `immer.js`Michel Weststratebefore adoptionc4f5667

line 2why, one step back
2import produce, {setUseProxies} from "../src/immer"

Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e

line 3why, one step back
3

Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0

lines 4–5why, one step back
4runTests("proxy", true)
5runTests("es5", false)

Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e

line 6why, one step back
6

Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0

line 7why, one step back
7function runTests(name, useProxies) {

Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e

line 8why, one step back
8 describe("curry - " + name, () => {

Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0

line 9why, one step back
9 setUseProxies(useProxies)

Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e

lines 10–11why, one step back
10
11 it("should check arguments", () => {

Merge branch 'patches'Michel Weststratebefore adoption2513fb8

line 12why, one step back
12 expect(() => produce()).toThrow(/produce expects 1 to 3 arguments/)

Implemented and document #108: allow returning values from producersMichel Weststratebefore adoptionc589ddd

lines 13–14why, one step back
13 expect(() => produce(new Buffer(""), () => {})).toThrow(
14 /the first argument to an immer producer should be a primitive, plain object or array/

Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e

lines 15–16why, one step back
15 )
16 expect(() => produce({}, () => {}, [])).toThrow(

Merge branch 'patches'Michel Weststratebefore adoption2513fb8

line 17why, one step back
17 /third argument of a producer/

Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e

line 18why, one step back
18 )

Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a

lines 19–20why, one step back
19 expect(() => produce({}, {})).toThrow(/should be a function/)
20 expect(() => produce({})).toThrow(

Merge pull request #121 from pkerschbaum/feature/initial-state-for-curry-fnMichel Weststratebefore adoption2cb5496

line 21why, one step back
21 /if first argument is not a function, the second argument to produce should be a function/

Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a

line 22why, one step back
22 )

Merge pull request #121 from pkerschbaum/feature/initial-state-for-curry-fnMichel Weststratebefore adoption2cb5496

lines 23–25why, one step back
23 expect(() => produce(() => {}, () => {})).toThrow(
24 /if first argument is a function .* the second argument to produce cannot be a function/25 )

Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e

lines 26–41why, one step back
26 })
2728 it("should support currying", () => {29 const state = [{}, {}, {}]30 const mapper = produce((item, index) => {31 item.index = index32 })3334 expect(state.map(mapper)).not.toBe(state)35 expect(state.map(mapper)).toEqual([36 {index: 0},37 {index: 1},38 {index: 2}39 ])40 expect(state).toEqual([{}, {}, {}])41 })

Fixed #105: Curried reducers not returning new statesMichel Weststratebefore adoptionc850b2f

lines 42–51why, one step back
42
43 it("should support returning new states from curring", () => {44 const reducer = produce((item, index) => {45 if (!item) {46 return {hello: "world"}47 }48 item.index = index49 })5051 expect(reducer(undefined, 3)).toEqual({hello: "world"})

Merge pull request #121 from pkerschbaum/feature/initial-state-for-curry-fnMichel Weststratebefore adoption2cb5496

lines 52–63why, one step back
52 expect(reducer({}, 3)).toEqual({index: 3})
53 })5455 it("should support passing an initial state as second argument", () => {56 const reducer = produce(57 (item, index) => {58 item.index = index59 },60 {hello: "world"}61 )6263 expect(reducer(undefined, 3)).toEqual({hello: "world", index: 3})

Fixed #105: Curried reducers not returning new statesMichel Weststratebefore adoptionc850b2f

lines 64–65why, one step back
64 expect(reducer({}, 3)).toEqual({index: 3})
65 })

Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e

lines 66–67why, one step back
66 })
67}