@gedit/utils
Advanced tools
Comparing version 0.1.20 to 0.1.22
@@ -7,2 +7,7 @@ import { Disposable } from './disposable'; | ||
/** | ||
* 从缓存中获取 | ||
* @param key | ||
*/ | ||
getFromCacheByKey(key: string): T | undefined; | ||
/** | ||
* 清空缓存数据 | ||
@@ -9,0 +14,0 @@ */ |
@@ -90,2 +90,5 @@ "use strict"; | ||
}, | ||
getFromCacheByKey: function (key) { | ||
return cache.find(function (item) { return item.key === key; }); | ||
}, | ||
dispose: function () { | ||
@@ -92,0 +95,0 @@ cache.forEach(function (item) { return item.dispose && item.dispose(); }); |
@@ -0,1 +1,16 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2017 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import { Emitter, Event } from './event'; | ||
@@ -35,2 +50,13 @@ export interface Disposable { | ||
} | ||
/** | ||
* 代理指定的事件 | ||
*/ | ||
export declare class EmitterProxy<T> implements Disposable { | ||
private originEvent; | ||
private toDispose; | ||
constructor(originEvent: Event<T>); | ||
private _event; | ||
get event(): Event<T>; | ||
dispose(): void; | ||
} | ||
//# sourceMappingURL=disposable.d.ts.map |
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DisposableCollection = exports.DisposableImpl = exports.Disposable = void 0; | ||
exports.EmitterProxy = exports.DisposableCollection = exports.DisposableImpl = exports.Disposable = void 0; | ||
/******************************************************************************** | ||
@@ -25,3 +19,2 @@ * Copyright (C) 2017 TypeFox and others. | ||
********************************************************************************/ | ||
var inversify_1 = require("inversify"); | ||
var event_1 = require("./event"); | ||
@@ -65,5 +58,2 @@ var Disposable; | ||
}); | ||
DisposableImpl = __decorate([ | ||
inversify_1.injectable() | ||
], DisposableImpl); | ||
return DisposableImpl; | ||
@@ -151,2 +141,33 @@ }()); | ||
exports.DisposableCollection = DisposableCollection; | ||
/** | ||
* 代理指定的事件 | ||
*/ | ||
var EmitterProxy = /** @class */ (function () { | ||
function EmitterProxy(originEvent) { | ||
this.originEvent = originEvent; | ||
this.toDispose = new DisposableCollection(); | ||
} | ||
Object.defineProperty(EmitterProxy.prototype, "event", { | ||
get: function () { | ||
var _this = this; | ||
if (!this._event) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
this._event = Object.assign(function (listener, thisArgs, disposables) { | ||
var originDisposable = _this.originEvent(listener, thisArgs, disposables); | ||
return _this.toDispose.push(originDisposable); | ||
}, { | ||
maxListeners: this.originEvent.maxListeners | ||
}); | ||
} | ||
return this._event; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
EmitterProxy.prototype.dispose = function () { | ||
this.toDispose.dispose(); | ||
}; | ||
return EmitterProxy; | ||
}()); | ||
exports.EmitterProxy = EmitterProxy; | ||
//# sourceMappingURL=disposable.js.map |
@@ -16,4 +16,4 @@ /******************************************************************************** | ||
********************************************************************************/ | ||
import { Disposable } from './disposable'; | ||
import { MaybePromise } from './types'; | ||
import type { Disposable } from './disposable'; | ||
import type { MaybePromise } from './types'; | ||
/** | ||
@@ -53,13 +53,2 @@ * Represents a typed event. | ||
} | ||
/** | ||
* 代理指定的事件 | ||
*/ | ||
export declare class EmitterProxy<T> implements Disposable { | ||
private originEvent; | ||
private toDispose; | ||
constructor(originEvent: Event<T>); | ||
private _event; | ||
get event(): Event<T>; | ||
dispose(): void; | ||
} | ||
export declare class Emitter<T = any> { | ||
@@ -66,0 +55,0 @@ private _options?; |
@@ -85,5 +85,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WaitUntilEvent = exports.Emitter = exports.EmitterProxy = exports.Event = void 0; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
var disposable_1 = require("./disposable"); | ||
exports.WaitUntilEvent = exports.Emitter = exports.Event = void 0; | ||
var Event; | ||
@@ -214,32 +212,2 @@ (function (Event) { | ||
}()); | ||
/** | ||
* 代理指定的事件 | ||
*/ | ||
var EmitterProxy = /** @class */ (function () { | ||
function EmitterProxy(originEvent) { | ||
this.originEvent = originEvent; | ||
this.toDispose = new disposable_1.DisposableCollection(); | ||
} | ||
Object.defineProperty(EmitterProxy.prototype, "event", { | ||
get: function () { | ||
var _this = this; | ||
if (!this._event) { | ||
this._event = Object.assign(function (listener, thisArgs, disposables) { | ||
var originDisposable = _this.originEvent(listener, thisArgs, disposables); | ||
return _this.toDispose.push(originDisposable); | ||
}, { | ||
maxListeners: this.originEvent.maxListeners | ||
}); | ||
} | ||
return this._event; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
EmitterProxy.prototype.dispose = function () { | ||
this.toDispose.dispose(); | ||
}; | ||
return EmitterProxy; | ||
}()); | ||
exports.EmitterProxy = EmitterProxy; | ||
var Emitter = /** @class */ (function () { | ||
@@ -246,0 +214,0 @@ function Emitter(_options) { |
{ | ||
"name": "@gedit/utils", | ||
"version": "0.1.20", | ||
"version": "0.1.22", | ||
"license": "MIT", | ||
@@ -30,3 +30,3 @@ "main": "lib/common/index", | ||
}, | ||
"gitHead": "4ec3420768cf24d1352dde3e2eec235cc7c4775a" | ||
"gitHead": "65f9de6fdb3df80ff2d8d327d8b56758e4f9f85d" | ||
} |
@@ -10,2 +10,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/** | ||
* 从缓存中获取 | ||
* @param key | ||
*/ | ||
getFromCacheByKey(key: string): T | undefined | ||
/** | ||
* 清空缓存数据 | ||
@@ -113,2 +118,5 @@ */ | ||
}, | ||
getFromCacheByKey(key: string): T | undefined { | ||
return cache.find(item => item.key === key); | ||
}, | ||
dispose(): void { | ||
@@ -115,0 +123,0 @@ cache.forEach(item => item.dispose && item.dispose()); |
@@ -16,4 +16,3 @@ /******************************************************************************** | ||
********************************************************************************/ | ||
import { injectable } from 'inversify'; | ||
import { Emitter, Event } from './event'; | ||
import { Emitter, Event, EventListener } from './event'; | ||
@@ -43,3 +42,2 @@ export interface Disposable { | ||
@injectable() | ||
export class DisposableImpl implements Disposable { | ||
@@ -128,1 +126,26 @@ readonly toDispose = new DisposableCollection(); | ||
} | ||
/** | ||
* 代理指定的事件 | ||
*/ | ||
export class EmitterProxy<T> implements Disposable { | ||
private toDispose = new DisposableCollection(); | ||
constructor(private originEvent: Event<T>) { | ||
} | ||
private _event: Event<T>; | ||
get event(): Event<T> { | ||
if (!this._event) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
this._event = Object.assign((listener: EventListener<T>, thisArgs?: any, disposables?: Disposable[]) => { | ||
const originDisposable = this.originEvent(listener, thisArgs, disposables); | ||
return this.toDispose.push(originDisposable); | ||
}, { | ||
maxListeners: this.originEvent.maxListeners | ||
}); | ||
} | ||
return this._event; | ||
} | ||
dispose(): void { | ||
this.toDispose.dispose(); | ||
} | ||
} | ||
@@ -19,4 +19,4 @@ /******************************************************************************** | ||
import { Disposable, DisposableCollection } from './disposable'; | ||
import { MaybePromise } from './types'; | ||
import type { Disposable } from './disposable'; | ||
import type { MaybePromise } from './types'; | ||
@@ -163,26 +163,2 @@ /** | ||
/** | ||
* 代理指定的事件 | ||
*/ | ||
export class EmitterProxy<T> implements Disposable { | ||
private toDispose = new DisposableCollection(); | ||
constructor(private originEvent: Event<T>) { | ||
} | ||
private _event: Event<T>; | ||
get event(): Event<T> { | ||
if (!this._event) { | ||
this._event = Object.assign((listener: EventListener<T>, thisArgs?: any, disposables?: Disposable[]) => { | ||
const originDisposable = this.originEvent(listener, thisArgs, disposables); | ||
return this.toDispose.push(originDisposable); | ||
}, { | ||
maxListeners: this.originEvent.maxListeners | ||
}); | ||
} | ||
return this._event; | ||
} | ||
dispose(): void { | ||
this.toDispose.dispose(); | ||
} | ||
} | ||
export class Emitter<T = any> { | ||
@@ -189,0 +165,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
527187
10008