跳到主要内容

setState 设置状态

setState

类型: MethodDeclaration

所属类: CommandFunctionList

定义位置: command.ts

描述

设置状态

参数

参数名类型描述默认值
\{ state, operation, time, \}{
	state: [`StateGetter`](https://github.com/Open-Yami-Community/open-yami-doc/blob/main/i18n/zh/docusaurus-plugin-content-docs/current/script/yami/yami.command.d.ts#L211);
operation: string;
time: number \| [`VariableGetter`](https://github.com/Open-Yami-Community/open-yami-doc/blob/main/i18n/zh/docusaurus-plugin-content-docs/current/script/yami/yami.command.d.ts#L87);
} | - | - |

返回值

类型: CommandFunction

源代码

位置: 第 5828 行

protected setState({
state,
operation,
time,
}: {
state: StateGetter;
operation: string;
time: number | VariableGetter;
}): CommandFunction {
const getState = Command.compileState(state);
const getTime = Command.compileNumber(time);
switch (operation) {
case "set-time":
return () => {
getState()?.setTime(getTime());
return true;
};
case "increase-time":
return () => {
getState()?.increaseTime(getTime());
return true;
};
case "decrease-time":
return () => {
getState()?.decreaseTime(getTime());
return true;
};
}
throw new Error("Compiling Error");
}

文档生成时间:2026/2/1 16:51:39