Skip to content

Instantly share code, notes, and snippets.

@Dema
Last active October 24, 2018 07:41
Show Gist options
  • Save Dema/2a777e007d5b378bbd71fad3d8516076 to your computer and use it in GitHub Desktop.
Save Dema/2a777e007d5b378bbd71fad3d8516076 to your computer and use it in GitHub Desktop.
getIn vs toJS
var Benchmark = require( 'benchmark')
var Immutable = require("immutable")
var suite = new Benchmark.Suite;
var json = {
"hello": [
{
"type": 50.087977,
"longitude": 72.167197,
"tags": [
"nulla",
"ullamco"
],
"friends": [
{
"id": 0,
"name": "Robinson Woods"
},
{
"id": 1,
"name": "Lottie Hogan"
}
]
},
{
"optionalField": "hello",
"type": 47.460772,
"longitude": 85.95137,
"tags": [
"aliqua",
"nulla"
],
"friends": [
{
"id": 0,
"name": "Mamie Wyatt"
},
{
"id": 1,
"name": "Alejandra Mcdaniel"
}
]
}
]
}
var state = Immutable.fromJS(json)
// add tests
suite.add('getIn', function() {
var friends = state.getIn(['hello', 'friends'])
var tags = state.getIn(['hello', 'tags'])
})
.add('.toJS', function() {
const {friends, tags}= state.getIn(['hello']).toJS()
})
// add listeners
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
// run async
.run({ 'async': true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment