immutable.js

Angular2-Webpack-Typescript - 3rd party libraries

試著忘記壹切 提交于 2019-12-12 15:08:59
问题 I've started with a beautiful seed project: https://github.com/AngularClass/angular2-webpack-starter And I've stuck with using 3rd-party modules.Can someone help/explain how to properly add/use external modules to this project? For example, I'm adding 'immutable' using: npm install immutable --save After that, I'm trying to link that module inside a component: import * as immutable from 'immutable'; import {List} from 'immutable'; import Immutable = require('immutable'); Nothing helps, it

Delete object from ImmutableJS List based upon property value

人走茶凉 提交于 2019-12-12 08:21:24
问题 What would be the simplest way to delete an object from a List based on a value of a property? I'm looking for an equivalent of the $pull in MongoDB. My List looks simple like this: [{a: '1' , b: '1'},{a: '2' , b: '2'}] And I'd like to remove from the array the object with property a set to '1'. In MongoDB, I'd do it like this: Model.update({_id: getCorrectParentObj},{ $pull: {listIDeleteFrom: { a: '1' } } },(err, result)=>{}); How can I get the same result with ImmutableJS? 回答1: You could

How does immutable.js #get work?

冷暖自知 提交于 2019-12-12 05:28:35
问题 I know how Map() can create an empty Map object, but how does the get here work?? Does it mean it will get get the value from the active key and if there isn't a key there, it will create an empty Map object? Where is the docs for this? const activeSelector = createSelector( rootSelector, (root) => root.get('active', Map()) ); 回答1: Yes, that's how it works. In your example, if active is not a key, it will return a new Map. This is defined in the docs for get() Returns the value associated

How can I sort an ImmutableJS List object on multiple keys?

孤人 提交于 2019-12-12 05:00:01
问题 I have a list of work history objects that have start and end date fields. I need to sort by start and then by end . If the dates overlap between work history objects when I use back-to-back sort() functions, the order can potentially be off. I need a way to sort an ImmutableJS List by multiple keys where the second sort key is only processed when first key values are equal. I would have assumed that ImmutableJS would have a simpler way to handle this type of sorting. Here is what I came up

Sort Map/Hash by values, retaining keys

↘锁芯ラ 提交于 2019-12-12 02:49:27
问题 I am having a hell of a time finding an answer to this one. I would like to have a hash in JavaScript, like so: const hash = { a: 'A', c: 'C', b: 'B' } and I would like to sort the object by the value , such that it might become: const hash = { a: 'A', b: 'B', c: 'C', } now, I realize that POJSOs don't guarantee the order of their keys, so I was thinking of using immutableJS or some object that will guarantee the order of the keys in the hash. so I am looking for something like: var newHash =

Immutable.js structure (updating nested map)?

一曲冷凌霜 提交于 2019-12-11 12:51:26
问题 I have a deeply nested immutable structure with maps and lists. I'm not sure about the best way to update a nested map within the structure (the node with id:356). I create a function to search the list, I find the target map, I update it. But the structure stays intact!! any idea what I'm doing wrong? https://jsbin.com/sadoni/1/edit?js,console var structure = Immutable.fromJS( { someKey:{id:1}, links:[ {id:123, c:false, chd:[]}, {id:134, c:false, chd:[ {id:212, c:false, chd:[ {id:245, c

Immutable List and Typescript proper way to define an array of objects with type

痞子三分冷 提交于 2019-12-11 05:11:19
问题 Here is my JSON data which i get from the server [ { "property1": 1, "property2": "asd", "property3": 2 }, { "property1": 1, "property2": "asd", "property3": 2 }, { "property1": 1, "property2": "asd", "property3": 2 } ] I want to define Immutable List object which uses this interface export interface myObject { propert1: number, propert2: string, propert3: number } I tried something like this but its not working : private myObjectList: Immutable.List<myObject> = Immutable.List([]); and then

re-rendering issues when using HOC for loader

随声附和 提交于 2019-12-11 04:13:56
问题 I am building an app where there is tons of pages and each page needs loader icon to show when the data is coming from server but has not arrived yet but no content is shown if there is no data at all. I could show this without using Higher Order Component(HOC) with no problem but doing so in every component is tedious. I want the loader code be reusable so that i can use this in every component wherever needed. But I am facing the problem. If there is data, there is no issue. If there is no

Add an Item in OrderedMap with Immutable.js

好久不见. 提交于 2019-12-10 22:15:27
问题 How can I add an Item at the end of an OrderedMap ? I tried this.boxes = this.boxes.setIn(data); Thanks for any help 回答1: One possible way of doing it is using concat var boxes = Immutable.OrderedMap({ box1: { id:1 }, box2: { id:2 } }); var data = Immutable.fromJS({ box3: { id:3 } }); var newBoxes = boxes.concat(data); console.log(newBoxes.toJS()); Will print out: Object { box1: Object { id: 1 }, box2: Object { id: 2 }, box3: Object { id: 3 } } 回答2: An OrderedMap doesn't really have an "end"

Immutable.fromJS() is not deep

半腔热情 提交于 2019-12-10 21:38:14
问题 The description of Immutable.fromJS is: Deeply converts plain JS objects and arrays to Immutable Maps and Lists. But that's wrong. I have an object with the following structure. The capitalized items are ES6 classes. Foo prop1 prop2 bars Bar prop1 prop2 Bar prop1 prop2 bazes Baz prop1 prop2 bars Bar prop1 prop2 Bar prop1 prop2 Baz prop1 prop2 bars Bar prop1 prop2 Bar prop1 prop2 The result of Immutable.fromJS(foo) is a Map. The arrays bars and bazes are List s. However, each element of these