Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
379 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
const immer = require('immer'); | ||
const { produce } = require('immer'); | ||
|
||
const setWithArray = (obj, path, value) => { | ||
return produce(obj, (draftObj) => { | ||
let index = 0; | ||
const pathToTraverse = path.length - 1; | ||
for (; index < pathToTraverse; index++) { | ||
draftObj = draftObj[path[index]] || {}; | ||
} | ||
draftObj[path[index]] = value; | ||
}); | ||
}; | ||
|
||
const immerCase = { | ||
label: 'immer', | ||
setWithString: null, | ||
setWithArray: null, | ||
setWithString: (obj, path, value) => { | ||
const pathParts = path.split('.'); | ||
return setWithArray(obj, pathParts, value); | ||
}, | ||
setWithArray, | ||
setWithArrayString: (obj, path, value) => { | ||
const pathParts = path.split(/[\.\[\]]/).filter((token) => !!token); | ||
return setWithArray(obj, pathParts, value); | ||
}, | ||
}; | ||
|
||
module.exports = immerCase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = [ | ||
require('./immer'), | ||
require('./immutable'), | ||
require('./immutable-assign'), | ||
require('./lodash'), | ||
require('./seamless-immutable'), | ||
require('./tiny-immutable-set'), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
const setWith = require('lodash/setWith'); | ||
const clone = require('lodash/clone'); | ||
|
||
const lodashImmutableSet = (obj, path, value) => setWith(clone(obj), path, value, clone); | ||
const set = (obj, path, value) => setWith(clone(obj), path, value, clone); | ||
|
||
const lodashCase = { | ||
label: 'lodash', | ||
setWithString: lodashImmutableSet, | ||
setWithArray: lodashImmutableSet, | ||
setWithString: set, | ||
setWithArray: set, | ||
setWithArrayString: set, | ||
}; | ||
|
||
module.exports = lodashCase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const options = { | ||
/* How many times each scenario is run for each library */ | ||
numIterations: 100000, | ||
/* Whether to console.log while libraries and scenarios are running */ | ||
showLogs: true, | ||
/* Whether to console.warn if a library hasn't implemented a scenario */ | ||
showWarnings: true, | ||
|
||
// To check against order-of-execution issues, we can run libraries-for-each-scenario, scenarios-for-each-library, | ||
// or both. This is mostly to validate the benchmark runner itself. (Running both will double the number of | ||
// iterations, and it won't give you any more information since execution order doesn't matter.) | ||
loopLibrariesThenScenarios: true, | ||
loopScenariosThenLibraries: true, | ||
}; | ||
|
||
module.exports = options; |
Oops, something went wrong.