本文整理匯總了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>();
}