How to use the fromJS function from immutable
Find comprehensive JavaScript immutable.fromJS code examples handpicked from public code repositorys.
GitHub: guigrpa/timm
100 101 102 103 104 105 106 107 108 109
getAt: (arr, idx) => arr[idx], setAt: (arr, idx, val) => timm.replaceAt(arr, idx, val), }; _solImmutableJs = { init: () => Immutable.fromJS(INITIAL_OBJECT), // deep get: (obj, key) => obj.get(key), set: (obj, key, val) => obj.set(key, val), getDeep: (obj, key1, key2) => obj.getIn([key1, key2]), setDeep: (obj, key1, key2, val) => obj.setIn([key1, key2], val),
23
265
8
+ 13 other calls in file
117 118 119 120 121 122 123 124 125 126
this.key = options.key || utils.generateRandomKey(); this._queuedChange = false; this.current = options.data; if (!isImmutableStructure(this.current) || !this.current) { this.current = Immutable.fromJS(this.current || {}); } if (!!options.history) { this.history = Immutable.List.of(this.current);
21
374
0
GitHub: planttheidea/crio
43 44 45 46 47 48 49 50 51 52
obj.setIn(['data', 'value'], Math.random()); } }; exports.objectSetInImmutableJs = (cycles) => { const obj = ImmutableJs.fromJS({ data: {value} }); for (let i = 0; i < cycles; i++) {
12
212
0
+ 27 other calls in file
84 85 86 87 88 89 90 91 92 93
const TreeUtils = require('immutable-treeutils'); // import TreeUtils from 'immutable-treeutils'; let treeUtils = new TreeUtils(); let data = Immutable.fromJS({ id: 'root', name: 'My Documents', type: 'folder', childNodes: [
8
77
3
GitHub: ctr-lang/ctr
208 209 210 211 212 213 214 215 216 217
}, hasIn: function (key = []) { return this.map.hasIn(key); }, setIn: function (key = [], val) { this.map = this.map.setIn(key, Immutable.fromJS(val)); }, getIn: function (key = []) { const val = this.map.getIn(key); if (_.isUndefined(val) || val === null) { return null; }
0
26
3
+ 27 other calls in file
13 14 15 16 17 18 19 20 21 22 23 24 25
var CHANGE_EVENT = 'change'; var explicitStepHistory = ["begin"]; // components, prescribable var state = Immutable.fromJS({ elt: 0, q: "", options: { "ingredient": [],
17
13
8
+ 2 other calls in file
GitHub: 25th-floor/ttrack
7 8 9 10 11 12 13 14 15 16
mimeReg.register( 'application/json', { read(str) { return Immutable.fromJS(JSON.parse(str)); }, write(obj) { return JSON.stringify(obj.toJS());
4
4
10
4 5 6 7 8 9 10 11 12 13 14 15
var sample = require('lodash/sample'); var denormalize = require('../src').denormalize; var immutable = require('immutable'); var fromJS = immutable.fromJS; var Map = immutable.Map; var Record = immutable.Record; var List = immutable.List;
3
9
2
+ 8 other calls in file
29 30 31 32 33 34 35 36 37 38
set (key, value) { if (typeof key !== 'string') { throw new Error('key must be string.') } const pathArray = key.split('.') this.stateMap = this.stateMap.setIn(pathArray, Immutable.fromJS(value)) } setIn (path, value) { if (!Array.isArray(path)) {
3
5
1
+ 3 other calls in file
11 12 13 14 15 16 17 18 19 20
{ id: 1, type: "default", value: "New course available" }, { id: 2, type: "urgent", value: "New resume available" }, { id: 3, type: "urgent", value: "New data available" } ]; const state = fromJS({ filter: "DEFAULT", notifications: notificationsNormalizer([ { id: 1, isRead: false, type: "default", value: "New course available" }, { id: 2, isRead: false, type: "urgent", value: "New resume available" },
1
2
1
GitHub: DFFR-NT/dffrnt.utils
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308
CSE: '^', // replace REP: '=' }), P: { Mod: Imm.fromJS({ CLR: '@', IDX: '#', COL: '?' }), Prm: { CLR: { C: '', B: '', S: '', F: '' }, IDX: { P: '', '<': '', '>': '' }, COL: { C: '', W: '', R: '' }
0
1
2
+ 65 other calls in file
35 36 37 38 39 40 41 42 43
const fieldsToRemove = _.difference(prevFields, currentFields); let newList = prevList; fieldsToRemove.forEach((field) => { const index = newList.indexOf(field); const manager = new Manager(state, prevList, keys, index, fromJS(layout.attributes || {})); const attrToRemoveInfos = manager.attrToRemoveInfos; // Retrieve the removed item infos const arrayOfLastLineElements = manager.arrayOfEndLineElements; const isRemovingAFullWidthNode = attrToRemoveInfos.bootstrapCol === 12;
0
1
1
+ 4 other calls in file
143 144 145 146 147 148 149 150 151 152
case "ADD_SIMPLE": return state.push(Immutable.fromJS(action.entity)) case "REMOVE_SIMPLE": return state.filter(item => item[action.keyField] !== action.key); case "UPDATE_SIMPLE": return Immutable.fromJS([{ id : 235235, x : 5.23, y : 9, state : "complete" }]); default: return state; } }
0
1
0
+ 6 other calls in file
31 32 33 34 35 36 37 38 39 40
``` ## Nested maps ```js var nested = Immutable.fromJS({ user: { profile: { name: 'John' } } }) nested .mergeDeep({ user: { profile: { age: 90 } } }) .setIn([ 'user', 'profile', 'name' ], 'Jack')
0
1
2
+ 3 other calls in file
GitHub: BrowserSync/bs-latency
16 17 18 19 20 21 22 23 24
const ui = bs.ui; const optPath = config.OPT_PATH; var pluginActive = true; const itemsPath = config.OPT_PATH.concat('items'); const items = opts.routes && opts.routes.length ? Immutable.fromJS(opts.routes) : Immutable.List([]); var mutableItems = [];
0
2
3
GitHub: ethical-jobs/redux
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279
/** * Updates a modules filters * @return Object */ function updateFilters(state, filters) { return state.mergeDeep({ filters: Immutable.fromJS(filters) }); } /** * Clears a modules filters
1
0
2
+ 9 other calls in file
4 5 6 7 8 9 10 11 12 13 14 15
var _ = require('lodash'); const { Map, fromJS } = require('immutable'); describe('Test courseReducer.js', () => { const state = fromJS(coursesNormalizer([ { id: 1, name: "ES6", isSelected: false, credit: 60 }, { id: 2, name: "Webpack", isSelected: false, credit: 20 }, { id: 3, name: "React", isSelected: false, credit: 40 } ]));
0
0
1
604 605 606 607 608 609 610 611 612 613
const initialProfile = Immutable.fromJS({ bio: 'Working on Awesome Game' }); const replacementProfile = Immutable.fromJS({ bio: 'Working on Design' }); const profileWithId = Immutable.fromJS({
0
0
2
+ 224 other calls in file
GitHub: JaapRood/klein
515 516 517 518 519 520 521 522 523 524
* Create instance of the model * @param {Object} properties * @returns {Model} */ _factory(properties) { const immutable = Immutable.fromJS(properties); if (this.args.type && typeof this.args.type.factory === 'function') { return this.args.type.factory(immutable); } else {
0
0
2
+ 8 other calls in file
immutable.Map is the most popular function in immutable (1575 examples)