How to use the seamless-immutable.from function in seamless-immutable

To help you get started, we’ve selected a few seamless-immutable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vanmeegen / stimo / testimmutability / src / models / GraphSeamlessImmutable.ts View on Github external
this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
    this.selection = selection;
  }

  // some additional methods
  getRatio(): number {
    return this.width / this.height;
  }
}

export type GNode = ImmutableObject;
let gnodeMutable = new GNodeMutable("title",1,0,0,10,10);
const immutableNode:GNode = SeamlessImmutable.from(gnodeMutable);
const mutated:GNode = immutableNode.set("title","NewTitle");

export class Graph {
  nodes: Map;

  constructor(nodes: GNodeMutable[]) {
    this.nodes = Graph.createNodeMap(nodes);
  }

  static createNodeMap(nodes: GNodeMutable[]) {
    return Map(nodes.map(node => [node.id, SeamlessImmutable.from(node)]))
  }

  moveNodes(nodeIds: number[], dx: number, dy: number) {
    for (let nodeId of nodeIds) {
      var node: GNode = this.getNode(nodeId);
github tomzaku / react-native-cba-starter-kit / exampleTs / src / com / AppHeader / AppHeader.tsx View on Github external
({ theme, scene, scenes, index }) => {
		// console.log('>>>>', scene, scenes)
		const headerTitleStylePath = ['descriptor', 'options', 'headerTitleStyle']
		const headerStylePath = ['descriptor', 'options', 'headerStyle']
		const headerTintColorPath = ['descriptor', 'options', 'headerTintColor']
		// const headerTintColorPath = ['descriptor', 'options', 'headerTintColor']
		const headerTitleStyle = path(headerTitleStylePath)(scene) || theme.appStyle.toolbar.text
		const headerTintColor = path(headerTintColorPath)(scene) || theme.palette.toolbar.contrastText
		// const headerTintColor = path(headerTintColorPath)(scene) || theme.palette.toolbar.contrastText
		const headerStyle = path(headerStylePath)(scene) || theme.appStyle.toolbar.main
		// const headerTintColor = path(headerTitleStylePath)(scene) || theme.palette.appStyle.text
		const newScene = from(scene).setIn(headerTitleStylePath, headerTitleStyle)
									.setIn(headerStylePath, headerStyle)
									// .setIn(headerTintColorPath, headerTintColor)
									.setIn(headerTintColorPath, headerTintColor)
		// >>>>>>>>>>>>>>>>>>>>
		// For android
		// I don't know why error come from
		// I wonder why react-navigation also have 2: scene, scenes
		// So I will override both
		const sceneInScenes = path([index])(scenes)
		const newsceneInScenes = from(sceneInScenes).setIn(headerTitleStylePath, headerTitleStyle)
		.setIn(headerStylePath, headerStyle)
		.setIn(headerTintColorPath, headerTintColor)
		// <<<<<<<<<<<<
		const newScenes = from(scenes).set(index, newsceneInScenes)
		return {
			scene: newScene,
github tomzaku / react-native-cba-starter-kit / exampleTs / src / com / AppHeader / AppHeader.tsx View on Github external
// const headerTintColor = path(headerTitleStylePath)(scene) || theme.palette.appStyle.text
		const newScene = from(scene).setIn(headerTitleStylePath, headerTitleStyle)
									.setIn(headerStylePath, headerStyle)
									// .setIn(headerTintColorPath, headerTintColor)
									.setIn(headerTintColorPath, headerTintColor)
		// >>>>>>>>>>>>>>>>>>>>
		// For android
		// I don't know why error come from
		// I wonder why react-navigation also have 2: scene, scenes
		// So I will override both
		const sceneInScenes = path([index])(scenes)
		const newsceneInScenes = from(sceneInScenes).setIn(headerTitleStylePath, headerTitleStyle)
		.setIn(headerStylePath, headerStyle)
		.setIn(headerTintColorPath, headerTintColor)
		// <<<<<<<<<<<<
		const newScenes = from(scenes).set(index, newsceneInScenes)
		return {
			scene: newScene,
			scenes: newScenes,
		}
	},
)
github jasonhealy / react-native-typescript-starter / src / store / index.ts View on Github external
import * as SI from "seamless-immutable";
import { createStore, applyMiddleware, combineReducers, compose } from "redux";
import { composeWithDevTools } from "redux-devtools-extension";
import thunk from "redux-thunk";
import reducers from "../reducers";

// Set up store
const initialState: any = SI.from({});
const store: any = createStore(reducers, initialState, composeWithDevTools(
  applyMiddleware(thunk)
));

export default store;
github rintoj / react-ts / src / react-ts / hot-load.js View on Github external
module.exports = function hotLoad(appName) {
  const STATE_KEY = `${appName}-hmr-application-state-cache`;

  // load state when reloaded
  try {
    const cachedState = JSON.parse(window.localStorage.getItem(STATE_KEY) || '{}');
    Reflux.state = Immutable.from(cachedState);
    Reflux.stateStream.next(Reflux.state);
  } catch (e) {
    window.localStorage.setItem(STATE_KEY, undefined);
  }

  // save state on each change
  Reflux.stateStream.subscribe(state => window.localStorage
    .setItem(STATE_KEY, JSON.stringify(state)), undefined, undefined);
};
github planttheidea / crio / benchmarks / set.js View on Github external
exports.objectSetSeamlessImmutableJs = (cycles) => {
  const obj = seamlessImmutableJs.from({value});

  let newValue;

  for (let i = 0; i < cycles; i++) {
    newValue = Math.random();

    obj.set('value', newValue);
  }
};
github planttheidea / crio / benchmarks / set.js View on Github external
exports.arraySetSeamlessImmutableJs = (cycles) => {
  const arr = seamlessImmutableJs.from(array);
  const maxIndex = arr.length - 1;

  let index, newVal;

  for (let i = 0; i < cycles; i++) {
    index = ~~(Math.random() * maxIndex);
    newVal = Math.random();

    arr.set(index, newVal);
  }
};
github tomzaku / react-native-cba-starter-kit / exampleTs / src / app / authentication / redux / initialState.ts View on Github external
import { from, ImmutableObject } from 'seamless-immutable'

export const initialState = from({
	isAuthenticated: false,
})


export interface TAuthenticationState {
	isAuthenticated: boolean
}
github secret-tech / frontend-ico-dashboard / src / redux / modules / dashboard / dashboard.js View on Github external
import { from } from 'seamless-immutable';
import { createReducer, createAsyncAction } from '../../../utils/actions';

export const FETCH_DASHBOARD = 'dashboard/dashboard/FETCH_DASHBOARD';

export const fetchDashboard = createAsyncAction(FETCH_DASHBOARD);

const initialState = from({
  daysLeft: 0,
  ethBalance: '',
  raised: {
    BTC: '',
    ETH: '',
    USD: ''
  },
  tokenBalance: '',
  tokenPrice: {
    ETH: '',
    USD: ''
  },
  tokensSold: ''
});

export default createReducer({
github secret-tech / frontend-ico-dashboard / src / redux / modules / dashboard / txFee.js View on Github external
import { from } from 'seamless-immutable';
import { createReducer, createAsyncAction } from '../../../utils/actions';

export const FETCH_FEE = 'dashboard/txFee/FETCH_FEE';

export const fetchFee = createAsyncAction(FETCH_FEE);

const initialState = from({
  fetching: false,
  gasPrice: '',
  gas: '',
  expectedTxFee: '',
  minInvest: ''
});

export default createReducer({
  [fetchFee.REQUEST]: (state) => (
    state.merge({
      fetching: true
    })
  ),

  [fetchFee.SUCCESS]: (state, { payload }) => (
    state.merge({

seamless-immutable

Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects.

BSD-3-Clause
Latest version published 6 years ago

Package Health Score

62 / 100
Full package analysis

Popular seamless-immutable functions