immutable.js

How to construct subclasses of Immutable.Record?

夙愿已清 提交于 2019-12-19 16:59:15
问题 class Event extends Immutable.Record { constructor(text) { super({text: text, timestamp: Date.now()}); } } Calling new Event() seems to return a constuctor function: new Event('started').toString() "function Record(values){ if(values instanceof RecordType){ return values;} if(!(this instanceof RecordType)){ return new RecordType(values);} if(!hasInitialized){ hasInitialized=true; var keys=Object.keys(defaultValues); setProps(RecordTypePrototype,keys); RecordTypePrototype.size=keys.length;

Immutable.Map.deleteAll() is not a function

两盒软妹~` 提交于 2019-12-18 06:25:30
问题 Consider the following code: const person = Immutable.Map({ name: 'John', surname: 'Maverick', age: 39 }); const mutated = person.deleteAll(['name', 'age']); Expected result would be that mutated now is a new instance of Map with the keys name and age deleted. However, throws an exception: Uncaught TypeError: person.deleteAll is not a function When inspecting the available methods of Immutable.Map prototype, there is no deleteAll nor removeAll methods. Have they been removed? The method is

How to update a value of a nested object in a reducer?

无人久伴 提交于 2019-12-17 22:23:44
问题 I have built my state like so const list = { categories: { Professional: { active: false, names: [ { id: 1, name: "Golf", active: false }, { id: 2, name: "Ultimate Frisbee", active: false } ] }} In my action I have added an ID option so I would like to change the active status when the user clicks the option to do so I am using Immutable JS though not married to it. I am wondering how I could target the id of the object and update its active status in a reducer? I am also open to feedback on

React-Redux complex (deep) state objects

ぃ、小莉子 提交于 2019-12-17 21:53:20
问题 Given my initial redux state is : const state = { currentView: 'ROOMS_VIEW', navbarLinks: List([ {name: 'Rooms', key: 'ROOMS_VIEW'}, {name: 'Dev', key: ''} ]), roomListsSelected: {group: 0, item: 0}, roomLists: [ { name: "Filters", expanded: true, listItems: [ { icon: 'images/icon-warning.svg', name: 'Alerts', filter: room => room.hasAlert }, { icon: 'images/icon-playlist.svg', name: 'In Progress', filter: room => room.progress > 20 }, { icon: 'images/icon-playlist.svg', name: 'Almost Done',

Do Immutable.js or Lazy.js perform short-cut fusion?

妖精的绣舞 提交于 2019-12-17 17:32:28
问题 First, let me define what is short-cut fusion for those of you who don't know. Consider the following array transformation in JavaScript: var a = [1,2,3,4,5].map(square).map(increment); console.log(a); function square(x) { return x * x; } function increment(x) { return x + 1; } Here we have an array, [1,2,3,4,5] , whose elements are first squared, [1,4,9,16,25] , and then incremented [2,5,10,17,26] . Hence, although we don't need the intermediate array [1,4,9,16,25] , we still create it.

How to configure SystemJs for ImmutableJs to work in Angular 2 project

早过忘川 提交于 2019-12-13 17:36:18
问题 so i am trying to import ImmutableJs into my angular 2 project, i am using this kind of systemjs config (function(global) { // map tells the System loader where to look for things var map = { 'src/client': 'src/client', // 'dist', '@angular': 'node_modules/@angular', 'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api', 'rxjs': 'node_modules/rxjs', 'highcharts': 'node_modules/highcharts', 'angular2-highcharts': 'node_modules/angular2-highcharts', 'immutable': 'node_modules

React: use or not to use Immutable.js

喜你入骨 提交于 2019-12-13 12:35:04
问题 I've looked for Immutable.js motivation when using React.js. As I understand React.js should guarantee immutability of properties. But, I can change view properties in this demo: var Hello = React.createClass({ render: function() { var item = { prop: 128 }; return <Test item={item} />; } }); var Test = React.createClass({ render: function() { this.props.item = -2; // Don't throw any error return <div>{this.props.item}</div>; // Returns -2 instead of object } }); React.render(<Hello name=

Visualizing ImmutableJS data from Redux store in a graph

时间秒杀一切 提交于 2019-12-13 12:19:38
问题 I am working on a React and Redux application that uses ImmutableJS to store all of it's state. The app receives data from a sensor at about 100 Hz. I need to draw a graph that updates in real time and displays this data. I have been using React-Vis for the graph, the problem is that it takes an array of objects and not an ImmutableJS data structure. I have solved this by converting the ImmutableJS data structure to an array like this: const data = this.props.HEGPercentage.toIndexedSeq()

spread operator giving issue with typescript

落花浮王杯 提交于 2019-12-13 03:36:38
问题 I am trying to implement a redux store for my react-typescript app. I am having a problem in my reducer. In native react-apps I did the following reminders = [...state, reminder(action)]; return reminders; the spread operator works perfectly. and the new object is added to array immutably. with typescript this is not happening.(get an empty object instead of an array) I tried object.assign return (<any>Object).assign({}, state, reminder(action)); This replaces the current object rather then

deep access in plain objects with Immutable

孤街浪徒 提交于 2019-12-12 19:30:32
问题 Consider the following example: const stickers = new OrderedMap().set(1, {hero: "batman", name: "Bruce"}); stickers.getIn([1]); //=> { hero: 'batman', name: 'Bruce' } stickers.getIn([1, "hero"]); //=> undefined Why is the result of that second getIn undefined? The docs on ImmutableJS state: Plain JavaScript Object or Arrays may be nested within an Immutable.js Collection, and getIn() can access those values as well Therefore, it follows that it makes no difference if value of the OrderedMap