immutable.js

JSDoc with and Immutable.js datastructures in annotations

99封情书 提交于 2019-12-10 14:43:10
问题 I am returning Immutable.js List data structure from function. PHPStorm is automatically attaching following @returns {*|List<T>|List<any>} . Eslint is giving me warning Unresolved variable of type 'T'. Where can I find documentation to annotations for Immutable.js? How can I describe in @returns annotation shape of the List that would pass in Eslint? /** * @param n * @returns {*|List<T>|List<any>} */ const getList = (n) => { let list = Immutable.List() for (let i = 0; i < n; i++) { for (let

How to loop through Immutable List like forEach?

放肆的年华 提交于 2019-12-10 12:31:45
问题 I would like to loop through Immutable List , I used List.map to do it, it can be worked, but not good. is there are a better way? Because I just check each element in array, if the element match my rule, I do something, just like Array.forEach , I don't want to return anything like Array.map . for example, it is my work now: let currentTheme = ''; let selectLayout = 'Layout1'; let layouts = List([{ name: 'Layout1', currentTheme: 'theme1' },{ name: 'Layout2', currentTheme: 'theme2' }])

Best way to remove an element from a List inside of a Map in Immutable.js

天大地大妈咪最大 提交于 2019-12-10 03:16:59
问题 I am using Facebook's Immutable.js to speed up my React application to take advantage of the PureRender mixin. One of my data structures is a Map() and one of the keys in that map has a List<Map>() as its value. What I'm wondering is, not knowing the index of the item I want to remove from the List() , what is the best way to go about removing it? So far I have come up with the below. Is this the best (most efficient) way? // this.graphs is a Map() which contains a List<Map>() under the key

Immutable.js Map values to array

无人久伴 提交于 2019-12-09 14:06:04
问题 I am using the immutable Map from http://facebook.github.io/immutable-js/docs/#/Map I need to get an array of the values out to pass to a backend service and I think I am missing something basic, how do I do it ? I have tried : mymap.valueSeq().toArray() But I still get an immutable data structure back ? For example : var d = '[{"address":"10.0.35.118","cpus":4}]'; var sr = JSON.parse(d); var is = Immutable.fromJS(sr); console.log(sr); console.log(is.toArray()); console.log(is.valueSeq()

How to create a map of records from a javascript raw object with Immutable.js?

点点圈 提交于 2019-12-08 15:59:38
问题 I'm new to immutable.js and I'd like to understand better how to use records starting from a raw JS object. With Immutable.fromJS() I can create a map passing a raw object, for example: var images = { "1": { id: "1", urls: ["/medium/1.jpg", "/large/1.jpg"] }, "2": { id: "2", urls: ["/medium/1.jpg", "/large/1.jpg"] } } var imagesMap = Immutable.fromJS(images); imagesMap is now a map containing other maps, one for each image. I'd like instead to create a map containing records, for example

Redux form: REGISTER_FIELD / UNREGISTER_FIELD get called after change or focus events

让人想犯罪 __ 提交于 2019-12-07 06:13:38
问题 I’m using Redux Form to render and handle form events in my React app. The following things are used: Initial values Field arrays Immutable.js Material UI Also, the field arrays are build using the initial values. export default connect( state => { return { buttonVisible, confirm, initialValues: Immutable.Map({ configuration_items: configuration_items, }) } } )(AssetConfiguration) The problem is that all the fields in the form get deregistered and registered on every change or focus event.

Redux not updating components when deep Immutable state properties are updated

我们两清 提交于 2019-12-07 01:10:38
问题 MY QUESTION: Why doesn't updating a property of an object in an array in my Immutable state (Map) not cause Redux to update my component? I'm trying to create a widget that uploads files to my server, and my initial state (from inside my UploaderReducer which you will see below) object looks like this: let initState = Map({ files: List(), displayMode: 'grid', currentRequests: List() }); I have a thunk method that starts uploads and dispatches actions when an event occurs (such as a progress

Custom equality semantics for Immutable.js data structures

风格不统一 提交于 2019-12-06 23:27:41
问题 I would like Sanctuary to provide Fantasy Land -compatible Map and Set types with value-based equality semantics. Ideally these values would be immutable, though this is not critical since Sanctuary would provide pure functions for merging and otherwise manipulating these values. I would love to leverage the good work done by the Immutable.js team; I imagine implementing persistent data structures takes considerable effort! The API provided by Immutable.js is of little importance since

Immutable.js Push into array in nested object

不羁岁月 提交于 2019-12-06 17:00:33
问题 Assume there is an object: const object = { 'foo': { 'bar': [1, 2, 3] } } I need to push 4 to object.foo.bar array. Right now I'm doing it like this: const initialState = Immutable.fromJS(object) const newState = initialState.setIn( ['foo', 'bar', object.foo.bar.length], 4 ) console.log(newState.toJS()) But I don't really like it, since I need to use object.foo.bar.length in the path. In my real example object is nested much deeper, and getting array's length looks very ugly. Is there another

React: use or not to use Immutable.js

左心房为你撑大大i 提交于 2019-12-06 12:03:29
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="World" />, document.getElementById('container')); Update: thanks to @FelixKling, now I know that