immutable.js

How to update element inside List with ImmutableJS?

痞子三分冷 提交于 2019-11-27 17:13:47
Here is what official docs said updateIn(keyPath: Array<any>, updater: (value: any) => any): List<T> updateIn(keyPath: Array<any>, notSetValue: any, updater: (value: any) => any): List<T> updateIn(keyPath: Iterable<any, any>, updater: (value: any) => any): List<T> updateIn(keyPath: Iterable<any, any>, notSetValue: any, updater: (value: any) => any): List<T> There is no way normal web developer (not functional programmer) would understand that! I have pretty simple (for non-functional approach) case. var arr = []; arr.push({id: 1, name: "first", count: 2}); arr.push({id: 2, name: "second",

How to describe Immutable.js Map shape with Flow

三世轮回 提交于 2019-11-27 11:55:03
问题 I would like to describe the shape of a map using Immutable's flow type definitions. You can describe the shape of an object by: const stateShape: { id: number, isActive: boolean } = { id: 123, isActive: true }; Is there something similar for Immutable's Maps? 回答1: TL;DR; No, but using Records you can get Flow to typecheck the shape but not the types. Longform The correct answer would be: no, since maps don't have shapes (at least in Flow and Immutable) . But Immutable does have a type for

React performance: rendering big list with PureRenderMixin

梦想与她 提交于 2019-11-27 11:36:49
问题 I took a TodoList example to reflect my problem but obviously my real-world code is more complex. I have some pseudo-code like this. var Todo = React.createClass({ mixins: [PureRenderMixin], ............ } var TodosContainer = React.createClass({ mixins: [PureRenderMixin], renderTodo: function(todo) { return <Todo key={todo.id} todoData={todo} x={this.props.x} y={this.props.y} .../>; }, render: function() { var todos = this.props.todos.map(this.renderTodo) return ( <ReactCSSTransitionGroup

Index inside map() function

馋奶兔 提交于 2019-11-27 10:42:07
I am missing a option how to get the index number inside the map function using List from Immutable.js : var list2 = list1.map(mapper => { a: mapper.a, b: mapper.index??? }).toList(); Documentation shows that map() returns Iterable<number, M> . Is there any elegant way to what I need? Samuel Toh You will be able to get the current iteration index for the map API through its 2nd parameter. See also: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/map Parameters callback - Function that produces an element of the new Array, taking three arguments: 1) currentValue

What are disadvantages to using immutable state in React?

蹲街弑〆低调 提交于 2019-11-27 01:32:38
问题 I have built my first React application with stateful stores the "normal" way, and now I am looking into using an immutable global state like used in the Este starterkit. The state of all stores is kept together in a single immutable data structure Components have no state but access data in their render() based on a store getter function Stores are also stateless but mutate the global application state for their domain using a cursor. The top level app component listens for state changes,

How to use Immutable.js with redux?

≡放荡痞女 提交于 2019-11-26 23:53:10
问题 Redux framework is using reducers to change app state in response to an action. The key requirement is that a reducer cannot modify an existing state object; it must produce a new object. Bad Example : import { ACTIVATE_LOCATION } from './actions'; export let ui = (state = [], action) => { switch (action.type) { case ACTIVATE_LOCATION: state.activeLocationId = action.id; break; } return state; }; Good Example : import { ACTIVATE_LOCATION } from './actions'; export let ui = (state = [], action

Why is immutability so important (or needed) in JavaScript?

冷暖自知 提交于 2019-11-26 21:13:44
I am currently working on React JS and React Native frameworks. On the half way road I came across Immutability or the Immutable-JS library , when I was reading about Facebook's Flux and Redux implementation. The question is, why is immutability so important? What is wrong in mutating objects? Doesn't it make things simple? Giving an example, let us consider a simple News reader app with the opening screen being a list view of news headlines. If I set say an array of objects with a value initially I can't manipulate it. That's what immutability principle says, right? (Correct me if I am wrong.

How to update element inside List with ImmutableJS?

假如想象 提交于 2019-11-26 18:54:42
问题 Here is what official docs said updateIn(keyPath: Array<any>, updater: (value: any) => any): List<T> updateIn(keyPath: Array<any>, notSetValue: any, updater: (value: any) => any): List<T> updateIn(keyPath: Iterable<any, any>, updater: (value: any) => any): List<T> updateIn(keyPath: Iterable<any, any>, notSetValue: any, updater: (value: any) => any): List<T> There is no way normal web developer (not functional programmer) would understand that! I have pretty simple (for non-functional approach

Why is immutability so important (or needed) in JavaScript?

南笙酒味 提交于 2019-11-26 08:54:26
问题 I am currently working on React JS and React Native frameworks. On the half way road I came across Immutability or the Immutable-JS library, when I was reading about Facebook\'s Flux and Redux implementation. The question is, why is immutability so important? What is wrong in mutating objects? Doesn\'t it make things simple? Giving an example, let us consider a simple News reader app with the opening screen being a list view of news headlines. If I set say an array of objects with a value

Index inside map() function

℡╲_俬逩灬. 提交于 2019-11-26 07:18:47
问题 I am missing a option how to get the index number inside the map function using List from Immutable.js : var list2 = list1.map(mapper => { a: mapper.a, b: mapper.index??? }).toList(); Documentation shows that map() returns Iterable<number, M> . Is there any elegant way to what I need? 回答1: You will be able to get the current iteration's index for the map method through its 2nd parameter. Example: const list = [ 'h', 'e', 'l', 'l', 'o']; list.map((currElement, index) => { console.log("The