How to use the immutable.Stack function in immutable

To help you get started, we’ve selected a few 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 maryrosecook / code-lauren / src / lang / program-state.js View on Github external
function init(code, bc, builtinBindings) {
  var bcPointer = 0;

  var p = im.Map({
    exception: undefined,
    code: code,
    currentInstruction: undefined,
    stack: im.Stack(),
    callStack: im.List(), // can't be a stack because too much editing of head
    scopes: im.List(),
    heap: heapLib.create()
  });

  p = scope.addScope(p, im.Map(), undefined, false); // builtin scope, mouse, keyboard et
  p = createTopLevelBindings(p, builtinBindings);

  p = scope.addScope(p, im.Map(), BUILTIN_SCOPE_ID, true); // user top level scope
  p = pushCallFrame(p, bc, bcPointer, USER_TOP_LEVEL_SCOPE_ID);
  return p;
};
github Soreine / immutable-undo / lib / index.js View on Github external
value: T,
  merged: number=1 // Number of snapshots virtually contained in this one,
                   // including itself. It increases each time a snapshot is merged // with this one.
}
*/

/**
 * Default properties.
 */
const DEFAULTS = {
    // The previous states. Last is the closest to current (most
    // recent)
    undos: new List(), // List

    // The next states. Top is the closest to current (oldest)
    redos: new Stack(), // Stack

    // Remember the current merged count. For SMOOTH strategy
    merged: 1,

    maxUndos: MAX_UNDOS,
    strategy: lru
};

/**
 * Data structure for an History of state, with undo/redo.
 */
class History extends new Record(DEFAULTS) {

    static lru = lru;
    static smooth = smooth;
github bcherny / undux / test / utils.ts View on Github external
test('isImmutable', t => {
  t.is(isImmutable(Immutable.List()), true)
  t.is(isImmutable(Immutable.Map()), true)
  t.is(isImmutable(Immutable.OrderedMap()), true)
  t.is(isImmutable(Immutable.Set()), true)
  t.is(isImmutable(Immutable.OrderedSet()), true)
  t.is(isImmutable(Immutable.Stack()), true)
  t.is(isImmutable(Immutable.Range()), true)
  t.is(isImmutable(Immutable.Repeat('a')), true)
  t.is(isImmutable(Immutable.Record({})()), true)
  t.is(isImmutable(Immutable.Seq()), true)
  t.is(isImmutable(Immutable.Seq.Keyed()), true)
  t.is(isImmutable(Immutable.Seq.Indexed()), true)
  t.is(isImmutable(Immutable.Seq.Set()), true)
  t.is(isImmutable(true), false)
  t.is(isImmutable([]), false)
  t.is(isImmutable({}), false)
  t.is(isImmutable(Object.freeze({})), false)
  t.is(isImmutable(() => {}), false)
  t.is(isImmutable(null), false)
  t.is(isImmutable(undefined), false)
  t.is(isImmutable('a'), false)
  t.is(isImmutable(42), false)
github Simon-Initiative / authoring-client / src / types / document.ts View on Github external
editingAllowed?: boolean;
  currentPage?: Maybe;
  currentNode?: Maybe;
  isSaving?: boolean;
  lastRequestSucceeded?: Maybe;
  saveCount?: number;
};

const defaultContent = {
  documentId: '',
  document: null,
  hasFailed: false,
  persistence: null,
  error: null,
  activeContentGuid: Maybe.nothing(),
  undoStack: Immutable.Stack(),
  redoStack: Immutable.Stack(),
  undoRedoGuid: createGuid(),
  editingAllowed: false,
  currentPage: Maybe.nothing(),
  currentNode: Maybe.nothing(),
  isSaving: false,
  lastRequestSucceeded: Maybe.nothing(),
  saveCount: 0,
};

export class EditedDocument extends Immutable.Record(defaultContent) {

  documentId: string;
  document: Document;
  hasFailed: boolean;
  error: string;
github nullobject / risk / src / Graph.js View on Github external
function reconstructPath (k, path) {
    let result = Stack()

    return k !== null
      ? reconstructPath_(result, path, k)
      : result

    function reconstructPath_ (result, path, k) {
      const j = path.get(k)

      result = result.unshift(k)

      return j !== null
        ? reconstructPath_(result, path, j)
        : result
    }
  }
}
github reindexio / reindex-api / schema / fields / SchemaConnectionField.js View on Github external
  convertNode(schema, node, parents, actualTypes = Stack()) {
    return new TConnection({
      name: node.name,
      alias: node.alias,
      type: this.type,
      reverseName: this.reverseName,
      call: processParameters(schema, 'connection', node.parameters),
      children: node.children.map((child) => {
        return child.toTyped(
          schema,
          List.of('connection'),
          Stack.of(this.type) || actualTypes
        );
      }),
    });
  }
}
github ianstormtaylor / slate / packages / slate / src / models / history.js View on Github external
static fromJSON(object) {
    const { redos = [], undos = [] } = object

    const history = new History({
      redos: new Stack(redos.map(this.createOperationsList)),
      undos: new Stack(undos.map(this.createOperationsList)),
    })

    return history
  }
github avocode / json-immutable / src / deserialize.js View on Github external
function reviveIterable(key, iterInfo, options) {
  switch (iterInfo['__iterable']) {
  case 'List':
    return immutable.List(revive(key, iterInfo['data'], options))

  case 'Set':
    return immutable.Set(revive(key, iterInfo['data'], options))

  case 'OrderedSet':
    return immutable.OrderedSet(revive(key, iterInfo['data'], options))

  case 'Stack':
    return immutable.Stack(revive(key, iterInfo['data'], options))

  case 'Map':
    return immutable.Map(revive(key, iterInfo['data'], options))

  case 'OrderedMap':
    return immutable.OrderedMap(revive(key, iterInfo['data'], options))

  default:
    throw new Error(`Unknown iterable type: ${iterInfo['__iterable']}`)
  }
}
github ArkEcosystem / core / packages / core-storage / lib / storage.js View on Github external
createStack (value) {
    return immutable.Stack(value)
  }
github codejunkienick / starter-lapis / app / redux / reducers / app.js View on Github external
export default function app(state: Object = initialState, action: ReduxAction) {
  switch (action.type) {
    case TYPES.LOAD.SUCCESS:
      return state.merge(action.payload);
    case TYPES.CLEAR_NOTIFICATIONS:
      return state.set('notifications', Stack());
    case TYPES.ADD_NOTIFICATION:
      return state.update('notifications', notifications =>
        notifications.push(
          Map({
            title: action.payload.msg,
            datetime: Date.now(),
            unread: true,
            id: hash(action.payload.msg + notifications.size)
          })
        )
      );
    case TYPES.TOGGLE_NOTIFICATIONS:
      return state.updateIn(['ui', 'isNotificationsOpen'], val => !val);
    case TYPES.READ_ALL_NOTIFICATIONS:
      return state.update('notifications', notifications =>
        notifications.map(notification => notification.set('unread', false))