Example #1
0
    /**
     * 设置重做、撤销栈
     * @param baseState this.state.baseState
     * @param contentState 当前设置的新内容State,newContentState
     * @param isSetUndo 是否设置撤销栈,线性调整在调整过程中不记录堆栈,调整结束时手动记录调整开始位置的状态为撤销栈
     */
    static push(baseState: BaseState, contentState: ContentState, isSetUndo: boolean = true): BaseState {
        if (baseState.getCurrentContent() === contentState) {
            return baseState;
        }

        const currentContent: ContentState = baseState.getCurrentContent();
        let tempContentState: ContentState = baseState.getTempContentState();
        let undoStack: Stack<ContentState> = baseState.getUndoStack();
        const redoStack: Stack<ContentState> = baseState.getRedoStack();
        const newContent: ContentState = contentState;

        if (newContent !== currentContent && isSetUndo === true) {
            tempContentState = newContent;
            undoStack = undoStack.push(currentContent);
        }

        const editorStateChanges: any = {
            currentContent: newContent,
            tempContentState,
            undoStack,
            redoStack
        };

        return BaseState.set(baseState, editorStateChanges);
    }
Example #2
0
 it('push inserts at lowest index', () => {
   var s0 = Stack.of('a', 'b', 'c');
   var s1 = s0.push('d', 'e', 'f');
   expect(s0.size).toBe(3);
   expect(s1.size).toBe(6);
   expect(s1.toArray()).toEqual(['d', 'e', 'f', 'a', 'b', 'c']);
 });
Example #3
0
    /**
     * 重做
     * @param baseState 当前baseState
     */
    static redo(baseState: BaseState): BaseState {
        const redoStack: Stack<ContentState> = baseState.getRedoStack();
        const newCurrentContent: ContentState = redoStack.peek();
        if (!newCurrentContent) {
          return baseState;
        }

        const currentContent: ContentState = baseState.getCurrentContent();

        return BaseState.set(baseState, {
            currentContent: newCurrentContent,
            tempContentState: newCurrentContent,
            undoStack: baseState.getUndoStack().push(currentContent),
            redoStack: redoStack.shift()
        });
    }
Example #4
0
export const createInterpreter = (): InterpreterState => {
  const globalEnv: Scope = {
    name: '_global_',
    parent: undefined,
    environment: Map<string, any>()
  }

  return new InterpreterState({
    _done: false,
    _isReturned: false,
    _result: undefined,
    isRunning: true,
    frames: Stack.of(0),
    scopes: Map.of(0, globalEnv),
    errors: List(),
    value: undefined,
    node: undefined
  })
}
Example #5
0
  it('iterable', () => {
    var s = Stack.of('a', 'b', 'c');
    expect(s.size).toBe(3);

    var forEachResults = [];
    s.forEach((val, i) => forEachResults.push([i, val]));
    expect(forEachResults).toEqual([
      [0,'a'],
      [1,'b'],
      [2,'c'],
    ]);

    // map will cause reverse iterate
    expect(s.map(val => val + val).toArray()).toEqual([
      'aa',
      'bb',
      'cc',
    ]);

    var iteratorResults = [];
    var iterator = s.entries();
    var step;
    while (!(step = iterator.next()).done) {
      iteratorResults.push(step.value);
    }
    expect(iteratorResults).toEqual([
      [0,'a'],
      [1,'b'],
      [2,'c'],
    ]);

    iteratorResults = [];
    iterator = s.toSeq().reverse().entries();
    while (!(step = iterator.next()).done) {
      iteratorResults.push(step.value);
    }
    expect(iteratorResults).toEqual([
      [0,'c'],
      [1,'b'],
      [2,'a'],
    ]);
  });
Example #6
0
 constructor(init: T, private _onChange?: (e: T) => void)
 {
     this._history = Immutable.Stack.of<T>(init);
     this._redoHistory = Immutable.Stack<T>();
 }
Example #7
0
 it('slice helpers make for easier to read code', () => {
   var s = Stack.of('a', 'b', 'c');
   expect(s.rest().toArray()).toEqual(['b', 'c']);
 });
Example #8
0
 it('get helpers make for easier to read code', () => {
   var s = Stack.of('a', 'b', 'c');
   expect(s.first()).toBe('a');
   expect(s.last()).toBe('c');
   expect(s.peek()).toBe('a');
 });
Example #9
0
 it('pushing creates a new instance', () => {
   var s0 = Stack.of('a');
   var s1 = s0.push('A');
   expect(s0.get(0)).toBe('a');
   expect(s1.get(0)).toBe('A');
 });
Example #10
0
 it('toArray provides a JS array', () => {
   var s = Stack.of('a', 'b', 'c');
   expect(s.toArray()).toEqual(['a', 'b', 'c']);
 });