@alphabetabc/core2
v0.1.6
Published
JavaScript Common Library
Downloads
3
Readme
@alphabetabc/core2
import {
//
Timer,
BatchUpdate,
EventDispatcher,
createEventDispatcher,
UiComponent,
bindContext,
domUtils,
} from '@alphabetabc/core2';
timer
const timer = new Timer(delay, [count?, callback?]);
const timer = new Timer(1000, 10); // interval
const timer = new Timer(Timer.REQUEST_ANIMATION_FRAME); // requestAnimationFrame
timer.runningStatus // boolean
timer.start();
timer.stop();
timer.reset();
timer.clear();
timer.addListener(e => {
console.log(e); // { type:"timer|completed", count?:number }
});
timer.on('timer',() => {});
timer.on('completed',() => {})
BatchUpdate
const bu = new BatchUpdate();
const updater = () => {
console.log('log------update');
};
bu.addUpdater(updater);
bu.removeUpdater(updater);
bu.update();
EventDispatcher
直接使用
const dispatch = new EventDispatcher();
dispatch.once(Symbol.for('click'), (...args) => {
console.log('log------------once', args);
});
dispatch.on(Symbol.for('click'), (...args) => {
console.log('log------------', args);
});
setTimeout(() => {
dispatch.emit(Symbol.for('click'), 666);
console.log('emit');
}, 1000);
setTimeout(() => {
dispatch.emit(Symbol.for('click'), 8888);
console.log('emit2');
}, 2000);
创建一个对象
const dispatcher = createEventDispatcher();
dispatcher.on('click', () => {});
dispatcher.emit('click', { value: 6666 });
装饰 function
const Obj: any = function () {};
EventDispatcher.Decorator()(Obj);
const obj = new Obj();
obj.on(Symbol.for('click2'), (...args) => {
console.log('log------------2222', args);
});
setTimeout(() => {
obj.emit(Symbol.for('click2'), 8888);
console.log('emit3');
}, 2000);
装饰 object
const Obj: any = {};
EventDispatcher.Decorator()(Obj);
const obj = Obj;
obj.on(Symbol.for('click2'), (...args) => {
console.log('log------------object', args);
});
setTimeout(() => {
obj.emit(Symbol.for('click2'), 8888);
console.log('object');
}, 2000);
类装饰器
@EventDispatcher.Decorator()
class P {}
const p1 = new P();
// @ts-ignore
p1.on('click', (...args) => {
console.log('log---------class', args);
});
// @ts-ignore
p1.emit('click', 6666);
const p2 = new P();
// @ts-ignore
// console.log(p2.on);
// console.log(p1.on);
// @ts-ignore
p2.emit('click', 6666);
console.log(p2);
UiComponent
// todo