@zhongguo168a/yxeditor-common 0.0.11 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1290,6 +1290,35 @@ declare class Dispatcher implements ISchedulable {
1290
1290
  protected typeToList: Dictionary<string, CallbackList<any>>;
1291
1291
  }
1292
1292
 
1293
+ declare class CallbackItem {
1294
+ listener: Function;
1295
+ caller: any;
1296
+ once: boolean;
1297
+ }
1298
+ declare class SampleCallbackList {
1299
+ constructor();
1300
+ dispose(): void;
1301
+ has(caller: any, listener: Function): boolean;
1302
+ protected getItem(caller: any, listener: Function): CallbackItem;
1303
+ /**
1304
+ * 监听事件,如果监听已经存在则返回
1305
+ * @param caller
1306
+ * @param listener 为了性能考虑, event使用了对象池处理。因此处理函数不应该保存event的引用。如有需要,可通过新建对象或Event.Clone()实现
1307
+ */
1308
+ on(caller: any, listener: (ctx: this, params?: any) => void): CallbackItem;
1309
+ once(caller: any, listener: (ctx: this, params?: any) => void): CallbackItem;
1310
+ protected offItem(item: CallbackItem): void;
1311
+ off(caller: any, listener: Function): void;
1312
+ offAll(type?: string): void;
1313
+ offAllCaller(caller: any): void;
1314
+ /**
1315
+ * 派发事件
1316
+ * @param params 事件参数
1317
+ */
1318
+ dispatch(params?: any): void;
1319
+ protected _callbackItems: CallbackItem[];
1320
+ }
1321
+
1293
1322
  declare class AssetURI {
1294
1323
  name: string;
1295
1324
  constructor(name: string);
@@ -1850,5 +1879,5 @@ declare const pathutil: PathUtil;
1850
1879
  declare function parsePlist(plist: any, texture: any): SpriteAtlas;
1851
1880
  declare function loadAtlas(url: any, callback: any): void;
1852
1881
 
1853
- export { ArrayUtil, AssetLoader, AssetURI, BitUtil, CallbackList, Controller, ControllerDict, ControllerSet, ConvertUtil, DictIterator, DictNode, DictSource, Dictionary, Dispatcher, ErrorUtil, EventItem, EventManager, EventUtil, Factory, FloatUtil, GeometryUtil, IdentUtil, LinkError, List, ListIterator, ListNode, ListSource, Listener, MapUtil, MathUtil, Model, Module, NetUtil, Page, PageController, PageEvent, PageLayer, PageList, PageRepo, PageState, PathUtil, Pool, RandUtil, Route, SamplePool, ScaleUtil, SimpleModel, StringUtil, TimeUtil, Timer, TreeIterator, TreeNode, TreeNodePlugin, TreeRoot, TreeRootPlugin, UIManager, UIObjectDict, UIPoolConfig, UISingleConfig, UIUtil, ViewController, XAssetManager, XEvent, arrayutil, assetx, bitutil, convertutil, ctrlrepo, errorutil, eventmgr, eventutil, floatutil, formatutil, geoutil, identutil, loadAtlas, maputil, mathutil, netutil, pagerepo, parseAtlas, parsePlist, pathutil, randutil, resutil, scaleutil, stringutil, timer, timeutil, uidict, uimgr, uiutil };
1882
+ export { ArrayUtil, AssetLoader, AssetURI, BitUtil, CallbackList, Controller, ControllerDict, ControllerSet, ConvertUtil, DictIterator, DictNode, DictSource, Dictionary, Dispatcher, ErrorUtil, EventItem, EventManager, EventUtil, Factory, FloatUtil, GeometryUtil, IdentUtil, LinkError, List, ListIterator, ListNode, ListSource, Listener, MapUtil, MathUtil, Model, Module, NetUtil, Page, PageController, PageEvent, PageLayer, PageList, PageRepo, PageState, PathUtil, Pool, RandUtil, Route, SampleCallbackList, SamplePool, ScaleUtil, SimpleModel, StringUtil, TimeUtil, Timer, TreeIterator, TreeNode, TreeNodePlugin, TreeRoot, TreeRootPlugin, UIManager, UIObjectDict, UIPoolConfig, UISingleConfig, UIUtil, ViewController, XAssetManager, XEvent, arrayutil, assetx, bitutil, convertutil, ctrlrepo, errorutil, eventmgr, eventutil, floatutil, formatutil, geoutil, identutil, loadAtlas, maputil, mathutil, netutil, pagerepo, parseAtlas, parsePlist, pathutil, randutil, resutil, scaleutil, stringutil, timer, timeutil, uidict, uimgr, uiutil };
1854
1883
  export type { CreatorFunction, DisposeFunction, IController, IEventManager, IExtend, IListItem, IModel, IModule, IModuleSample, ITreeListItem, RecycleFunction, error };
package/dist/index.esm.js CHANGED
@@ -4328,6 +4328,110 @@ class Dispatcher {
4328
4328
  }
4329
4329
  }
4330
4330
 
4331
+ class CallbackItem {
4332
+ }
4333
+ class SampleCallbackList {
4334
+ constructor() {
4335
+ this._callbackItems = [];
4336
+ }
4337
+ dispose() {
4338
+ this._callbackItems = null;
4339
+ }
4340
+ has(caller, listener) {
4341
+ return !!this.getItem(caller, listener);
4342
+ }
4343
+ getItem(caller, listener) {
4344
+ let items = this._callbackItems;
4345
+ for (const item of items) {
4346
+ if (item.caller == caller && item.listener == listener) {
4347
+ return item;
4348
+ }
4349
+ }
4350
+ return null;
4351
+ }
4352
+ /**
4353
+ * 监听事件,如果监听已经存在则返回
4354
+ * @param caller
4355
+ * @param listener 为了性能考虑, event使用了对象池处理。因此处理函数不应该保存event的引用。如有需要,可通过新建对象或Event.Clone()实现
4356
+ */
4357
+ on(caller, listener) {
4358
+ if (!listener) {
4359
+ throw new Error("listerner is null");
4360
+ }
4361
+ if (this.has(caller, listener)) {
4362
+ return;
4363
+ }
4364
+ let existed = this.getItem(caller, listener);
4365
+ if (existed) {
4366
+ return existed;
4367
+ }
4368
+ let item = new CallbackItem();
4369
+ item.caller = caller;
4370
+ item.listener = listener;
4371
+ let items = this._callbackItems;
4372
+ items.push(item);
4373
+ return item;
4374
+ }
4375
+ once(caller, listener) {
4376
+ if (!listener) {
4377
+ throw new Error("listerner is null");
4378
+ }
4379
+ if (this.has(caller, listener)) {
4380
+ return;
4381
+ }
4382
+ let item = new CallbackItem();
4383
+ item.caller = caller;
4384
+ item.listener = listener;
4385
+ item.once = true;
4386
+ let items = this._callbackItems;
4387
+ items.push(item);
4388
+ return item;
4389
+ }
4390
+ offItem(item) {
4391
+ this.off(item.caller, item.listener);
4392
+ }
4393
+ off(caller, listener) {
4394
+ let items = this._callbackItems;
4395
+ for (let i = 0; i < items.length; i++) {
4396
+ let item = items[i];
4397
+ if (item.caller !== caller) {
4398
+ continue;
4399
+ }
4400
+ if (listener !== listener) {
4401
+ continue;
4402
+ }
4403
+ items.splice(i, 1);
4404
+ return;
4405
+ }
4406
+ }
4407
+ offAll(type) {
4408
+ let items = this._callbackItems;
4409
+ if (!type) {
4410
+ items.length = 0;
4411
+ }
4412
+ }
4413
+ offAllCaller(caller) {
4414
+ let items = this._callbackItems;
4415
+ items = items.filter((value, index, array) => {
4416
+ return value.caller !== caller;
4417
+ });
4418
+ this._callbackItems = items;
4419
+ }
4420
+ /**
4421
+ * 派发事件
4422
+ * @param params 事件参数
4423
+ */
4424
+ dispatch(params) {
4425
+ let items = this._callbackItems;
4426
+ if (items.length == 0) {
4427
+ return;
4428
+ }
4429
+ for (let on of items) {
4430
+ on.listener.call(on.caller, this, params);
4431
+ }
4432
+ }
4433
+ }
4434
+
4331
4435
  function parseAtlas(name, plist, texture) {
4332
4436
  plist.meta;
4333
4437
  let frames = plist.frames;
@@ -5995,5 +6099,5 @@ class PathUtil {
5995
6099
  }
5996
6100
  const pathutil = new PathUtil();
5997
6101
 
5998
- export { ArrayUtil, AssetLoader, AssetURI, BitUtil, CallbackList, Controller, ControllerDict, ControllerSet, ConvertUtil, DictIterator, DictNode, DictSource, Dictionary, Dispatcher, ErrorUtil, EventItem, EventManager, EventUtil, Factory, FloatUtil, GeometryUtil, IdentUtil, LinkError, List, ListIterator, ListNode, ListSource, Listener, MapUtil, MathUtil, Model, Module, NetUtil, Page, PageController, PageEvent, PageLayer, PageList, PageRepo, PageState, PathUtil, Pool, RandUtil, Route, SamplePool, ScaleUtil, SimpleModel, StringUtil, TimeUtil, Timer, TreeIterator, TreeNode, TreeNodePlugin, TreeRoot, TreeRootPlugin, UIManager, UIObjectDict, UIPoolConfig, UISingleConfig, UIUtil, ViewController, XAssetManager, XEvent, arrayutil, assetx, bitutil, convertutil, ctrlrepo, errorutil, eventmgr, eventutil, floatutil, formatutil, geoutil, identutil, loadAtlas, maputil, mathutil, netutil, pagerepo, parseAtlas, parsePlist, pathutil, randutil, resutil, scaleutil, stringutil, timer, timeutil, uidict, uimgr, uiutil };
6102
+ export { ArrayUtil, AssetLoader, AssetURI, BitUtil, CallbackList, Controller, ControllerDict, ControllerSet, ConvertUtil, DictIterator, DictNode, DictSource, Dictionary, Dispatcher, ErrorUtil, EventItem, EventManager, EventUtil, Factory, FloatUtil, GeometryUtil, IdentUtil, LinkError, List, ListIterator, ListNode, ListSource, Listener, MapUtil, MathUtil, Model, Module, NetUtil, Page, PageController, PageEvent, PageLayer, PageList, PageRepo, PageState, PathUtil, Pool, RandUtil, Route, SampleCallbackList, SamplePool, ScaleUtil, SimpleModel, StringUtil, TimeUtil, Timer, TreeIterator, TreeNode, TreeNodePlugin, TreeRoot, TreeRootPlugin, UIManager, UIObjectDict, UIPoolConfig, UISingleConfig, UIUtil, ViewController, XAssetManager, XEvent, arrayutil, assetx, bitutil, convertutil, ctrlrepo, errorutil, eventmgr, eventutil, floatutil, formatutil, geoutil, identutil, loadAtlas, maputil, mathutil, netutil, pagerepo, parseAtlas, parsePlist, pathutil, randutil, resutil, scaleutil, stringutil, timer, timeutil, uidict, uimgr, uiutil };
5999
6103
  //# sourceMappingURL=index.esm.js.map