immer#finishDraft TypeScript Examples
The following examples show how to use
immer#finishDraft.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: update-model.ts From XFlow with MIT License | 6 votes |
/** 执行Cmd */
execute = async () => {
const ctx = this.contextProvider()
const { args, hooks: runtimeHook } = ctx.getArgs()
const hooks = ctx.getHooks()
const result = await hooks.updateModel.call(
args,
async handlerArgs => {
const { updateModel, getModel, modelService } = handlerArgs
const model = await getModel(modelService)
const currentValue = model.getValue()
const draft = createDraft(currentValue)
await updateModel(draft)
const newValue = finishDraft(draft)
model.setValue(newValue)
ctx.addUndo(
Disposable.create(async () => {
model.setValue(newValue)
}),
)
return { model, value: newValue }
},
runtimeHook,
)
ctx.setResult(result)
return this
}
Example #2
Source File: index.ts From yugong with MIT License | 6 votes |
function handlerAnimation(
animation: AnimationTypesOfStyleItems,
// 是否进入视区
inView?: boolean,
): AnimationTypesOfStyleItems {
const animationDraft = createDraft(animation);
// 动画元素是否有视觉区域观察者
// 或者有视觉区域观察者但动画没有设置元素可视时播放时
// 直接返回动画
if (inView === void 0 || animationDraft.animationPlayInView !== true)
return finishDraft(animationDraft);
// 离开视区时移除动画, 将内容做隐藏处理
const initAnimate: AnimationTypesOfStyleItems = {
animationName: 'initanimate',
animationDuration: 100,
animationIterationCount: 1,
animationPlayState: 'paused',
};
if (inView === false) {
return initAnimate;
}
// 有视觉区域观察者
const animationData = finishDraft(animationDraft);
return animationData;
}