How to use deep-freeze - 10 common examples

To help you get started, we’ve selected a few deep-freeze 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 jspsych / jsPsych-Redux-GUI / __tests__ / trialTableTests.jsx View on Github external
const test_SET_STATE = () => {
  const emptyState = {};  // Make an empty state
  deepFreeze(emptyState); // Ensure no mutations

  const stateToSet = {
    '0': Timeline
  };
  deepFreeze(stateToSet);

  const test_SET_STATE = trialTable(
    emptyState,
    {
      type: 'SET_STATE',
      state: {
        trialTable: stateToSet
      }
    });
  const soln_SET_STATE = {
    '0': Timeline
  };
  // The comment block below prevents eslint from complaining
  // about 'it' and 'expect' being undefined. 
  // (They are defined implicitly by jest)
github sourcecred / sourcecred / src / plugins / github / declaration.js View on Github external
// @flow

import deepFreeze from "deep-freeze";
import type {PluginDeclaration} from "../../analysis/pluginDeclaration";
import * as N from "./nodes";
import * as E from "./edges";
import dedent from "../../util/dedent";

export const repoNodeType = deepFreeze({
  name: "Repository",
  pluralName: "Repositories",
  prefix: N.Prefix.repo,
  defaultWeight: 4,
  description: "NodeType for a GitHub repository",
});

const issueNodeType = deepFreeze({
  name: "Issue",
  pluralName: "Issues",
  prefix: N.Prefix.issue,
  defaultWeight: 2,
  description: "NodeType for a GitHub issue",
});

const pullNodeType = deepFreeze({
github sourcecred / sourcecred / src / plugins / demo / graph.js View on Github external
// @flow

import deepFreeze from "deep-freeze";
import {Graph} from "../../core/graph";
import {partsNode, partsEdge} from "../../core/graphTestUtil";

export const nodes = deepFreeze({
  inserter1: partsNode(["factorio", "inserter", "1"]),
  machine1: partsNode(["factorio", "machine", "1"]),
  inserter2: partsNode(["factorio", "inserter", "2"]),
  machine2: partsNode(["factorio", "machine", "2"]),
});

export const edges = deepFreeze({
  transports1: partsEdge(
    ["factorio", "transports", "1"],
    nodes.inserter1,
    nodes.machine1
  ),
  transports2: partsEdge(
    ["factorio", "transports", "2"],
    nodes.inserter2,
    nodes.machine2
  ),
  assembles1: partsEdge(
    ["factorio", "assembles", "1"],
    nodes.machine1,
    nodes.inserter2
  ),
});
github ryelle / wordpress-query-posts / test / reducer.js View on Github external
it( 'should track the post IDs for additional requested queries', () => {
			const originalState = deepFreeze( { '{"paged":1}': [ 6, 5, 4, 3 ] } );
			const action = {
				type: POSTS_REQUEST_SUCCESS,
				query: { paged: 2 },
				posts: [ post ]
			};
			const newState = queries( originalState, action );
			expect( newState ).to.eql( {
				'{"paged":1}': [ 6, 5, 4, 3 ],
				'{"paged":2}': [ 7 ]
			} );
		} );
	} );
github linode / manager / test / reducers / datacenters.spec.js View on Github external
it('should handle UPDATE_DATACENTERS', () => {
    const state = datacenters(undefined, {});
    const dc = { id: 'datacenter_6', label: "Newark, NJ" };

    deepFreeze(state);

    expect(
      datacenters(state, {
        type: actions.UPDATE_DATACENTERS,
        response: {
          page: 1,
          total_pages: 1,
          datacenters: [ dc ]
        }
      })
    ).to.have.property('datacenters')
    .which.has.property('datacenter_6');
  });
});
github rainforestapp / tester-chrome-extension / src / constants.js View on Github external
SET_PLUGIN_VERSION: 'SET_PLUGIN_VERSION',
  SET_WORKER_PROFILE: 'SET_WORKER_PROFILE',
  CHANNEL_LEFT: 'CHANNEL_LEFT',
  SET_OPTIONS: 'SET_OPTIONS',
  RELOAD_PLUGIN: 'RELOAD_PLUGIN',
  NOTIFY: 'NOTIFY',
  CLEAR_NOTIFICATION: 'CLEAR_NOTIFICATION',
});

export const colors = deepFreeze({
  RED: [255, 0, 0, 230],
  GREEN: 'green',
  GREY: [0, 0, 0, 230],
});

export const REDUCERS = deepFreeze(['worker', 'socket', 'plugin', 'notifications']);

export const CONFIRM_WORK_ASSIGNMENT = 'confirmWorkAssignment';
export const NOTIFICATION_SOUND_URL = 'notificationSoundUrl';
export const NOTIFICATION_SOUND_REPEAT = 'notificationSoundRepeat';

const getChromeConfig = () => (
  {
    notificationIconUrl: window.CHROME_NOTIFICATION_ICON_URL,
    greyIcon: window.CHROME_GREY_ICON,
    colorIcon: window.CHROME_COLOR_ICON,
  }
);

const getConfig = () => {
  switch (window.ENV) {
    case 'dev':
github wisnuc / appifi / src / fruitmix / media / mediaShareData.js View on Github external
constructor(digest, doc) {

    this.digest = digest
    this.doc = doc

    deepFreeze(this)
  }
github sourcecred / sourcecred / src / plugins / git / edges.js View on Github external
}

export const Prefix = deepFreeze({
  base: GIT_PREFIX,
  hasParent: gitEdgeAddress(HAS_PARENT_TYPE),
});

export type HasParentAddress = {|
  type: typeof HAS_PARENT_TYPE,
  child: GitNode.CommitAddress,
  parent: GitNode.CommitAddress,
|};

export type StructuredAddress = HasParentAddress;

export const createEdge = deepFreeze({
  hasParent: (
    child: GitNode.CommitAddress,
    parent: GitNode.CommitAddress,
    timestampMs: number
  ): Edge => ({
    address: toRaw({type: HAS_PARENT_TYPE, child, parent}),
    src: GitNode.toRaw(child),
    dst: GitNode.toRaw(parent),
    timestampMs,
  }),
});

const NODE_PREFIX_LENGTH = NodeAddress.toParts(GitNode._gitAddress()).length;

function lengthEncode(x: GitNode.RawAddress): $ReadOnlyArray {
  const baseParts = NodeAddress.toParts(x).slice(NODE_PREFIX_LENGTH);
github kunukn / cube-two / src / assets / scripts / cube-two / cube-two.js View on Github external
b: temp.b.c4,
            r: backface,
            l: temp.l.c3,
        }
        cubeSkins.cubes[8] = {
            u: backface,
            d: temp.d.c4,
            f: backface,
            b: temp.b.c3,
            r: temp.r.c4,
            l: backface,
        }

        config.cubeSkins = cubeSkins;

        deepFreeze(config);
    }
github sourcecred / sourcecred / src / plugins / github / graphqlTypes.js View on Github external
| "HOORAY"
  | "LAUGH"
  | "ROCKET"
  | "THUMBS_DOWN"
  | "THUMBS_UP";

export const ReactionContent$Values: {|
  +CONFUSED: "CONFUSED",
  +EYES: "EYES",
  +HEART: "HEART",
  +HOORAY: "HOORAY",
  +LAUGH: "LAUGH",
  +ROCKET: "ROCKET",
  +THUMBS_DOWN: "THUMBS_DOWN",
  +THUMBS_UP: "THUMBS_UP",
|} = deepFreeze({
  CONFUSED: "CONFUSED",
  EYES: "EYES",
  HEART: "HEART",
  HOORAY: "HOORAY",
  LAUGH: "LAUGH",
  ROCKET: "ROCKET",
  THUMBS_DOWN: "THUMBS_DOWN",
  THUMBS_UP: "THUMBS_UP",
});

export type Ref = {|
  +__typename: "Ref",
  +id: string,
  +target: null | GitObject,
|};

deep-freeze

recursively Object.freeze() objects and functions

public domain
Latest version published 12 years ago

Package Health Score

62 / 100
Full package analysis

Popular deep-freeze functions