本文整理汇总了TypeScript中Immutable.Stack类的典型用法代码示例。如果您正苦于以下问题:TypeScript Stack类的具体用法?TypeScript Stack怎么用?TypeScript Stack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Stack类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: push
/**
* 设置重做、撤销栈
* @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);
}
示例2: it
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']);
});
示例3: redo
/**
* 重做
* @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()
});
}
示例4: InterpreterState
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
})
}
示例5: constructor
constructor(init: T, private _onChange?: (e: T) => void)
{
this._history = Immutable.Stack.of<T>(init);
this._redoHistory = Immutable.Stack<T>();
}