码迷,mamicode.com
首页 > Web开发 > 详细

[Immutable,js] Iterating Over an Immutable.js Map()

时间:2016-03-01 06:21:17      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:

Immutable.js provides several methods to iterate over an Immutable.Map(). These also apply to the other immutable structures found within the Immutable.js family, such as Set and List. The primary methods are map and forEach, but we will also cover filter and groupBy.

 

// map()
  return todos.map(todo => {
    return todo.text
  });

// filter()
  return todos.filter(todo => {
    return todo.completed;
  })


// groupBy() --> return new Immtuable Map
  return todos.groupBy(todo => {
    return todo.completed
  })

 

Notice, only forEach method will actually change its value!

// forEach()
function markAllTodosAsComplete(todos) {
  return todos.forEach(todo => {
    todo.completed = true
  });
}

 

[Immutable,js] Iterating Over an Immutable.js Map()

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/5229556.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!