本文整理汇总了TypeScript中change-emitter.createChangeEmitter函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createChangeEmitter函数的具体用法?TypeScript createChangeEmitter怎么用?TypeScript createChangeEmitter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createChangeEmitter函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: emitterOf3Args
function emitterOf3Args() {
const { emit, listen } = createChangeEmitter<string, boolean, number>();
const unlisten = listen((value, success, count) => { value.length > count === success });
emit("hello", true, 3);
unlisten();
}
开发者ID:Agamnentzar,项目名称:DefinitelyTyped,代码行数:9,代码来源:change-emitter-tests.ts
示例2: emitterOf1Args
function emitterOf1Args() {
const { emit, listen } = createChangeEmitter<string>();
const unlisten = listen(value => { value.length });
emit("hello");
unlisten();
}
开发者ID:Agamnentzar,项目名称:DefinitelyTyped,代码行数:9,代码来源:change-emitter-tests.ts
示例3: emitterOf2Args
function emitterOf2Args() {
const { emit, listen } = createChangeEmitter<string, boolean>();
const unlisten = listen((value, success) => { value.length > 0 === success });
emit("hello", true);
unlisten();
}
开发者ID:Agamnentzar,项目名称:DefinitelyTyped,代码行数:9,代码来源:change-emitter-tests.ts
示例4: emitterOf5Args
function emitterOf5Args() {
const { emit, listen } = createChangeEmitter<string, boolean, number, Date, string>();
const unlisten = listen((v1, v2, v3, v4, v5) => { });
emit("hello", true, 3, new Date(), "world");
unlisten();
}
开发者ID:Agamnentzar,项目名称:DefinitelyTyped,代码行数:9,代码来源:change-emitter-tests.ts
示例5: emitterOf0Args
function emitterOf0Args() {
const { emit, listen }: ChangeEmitterOf0 = createChangeEmitter();
const unlisten = listen(() => { });
// const unlisten = listen(value => {}); // SYNTAX ERROR
emit();
// emit("hello"); // SYNTAX ERROR
unlisten();
}
开发者ID:Agamnentzar,项目名称:DefinitelyTyped,代码行数:11,代码来源:change-emitter-tests.ts
示例6: usage
function usage() {
// https://github.com/acdlite/change-emitter#usage
const emitter = createChangeEmitter()
// Called `listen` instead of `subscribe` to avoid confusion with observable spec
const unlisten = emitter.listen((...args) => {
console.log(args)
})
emitter.emit(1, 2, 3) // logs `[1, 2, 3]`
unlisten()
emitter.emit(4, 5, 6) // doesn't log
}
开发者ID:Agamnentzar,项目名称:DefinitelyTyped,代码行数:14,代码来源:change-emitter-tests.ts
示例7: untypedEmitter
function untypedEmitter() {
const { emit, listen } = createChangeEmitter();
const unlisten0 = listen(() => {/* do something */});
const unlisten1 = listen(value => {/* do something with value */});
const unlisten2 = listen((value1, value2) => {/* do something with values */});
const unlistenArgs = listen((...args: any[]) => {/* do something with values */});
emit();
emit("hello");
emit("hello", "world");
emit(1, 2, 3, 4, 5);
unlisten0();
unlisten1();
unlisten2();
unlistenArgs();
}
开发者ID:Agamnentzar,项目名称:DefinitelyTyped,代码行数:18,代码来源:change-emitter-tests.ts
示例8: createChangeEmitter
const createStore = (reducer: Function, initialState: any) => {
let state = initialState
const emitter = createChangeEmitter()
function dispatch(action: any) {
state = reducer(state, action)
emitter.emit()
return action
}
function getState() {
return state
}
return {
dispatch,
getState,
subscribe: emitter.listen
}
}
开发者ID:Agamnentzar,项目名称:DefinitelyTyped,代码行数:20,代码来源:change-emitter-tests.ts
注:本文中的change-emitter.createChangeEmitter函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论