Comparing version 0.2.0 to 0.2.1
@@ -8,30 +8,34 @@ function generateDefaultState() { | ||
} | ||
export class YEvent { | ||
constructor() { | ||
var YEvent = /** @class */ (function () { | ||
function YEvent() { | ||
this.list = {}; | ||
} | ||
getState(type) { | ||
YEvent.prototype.getState = function (type) { | ||
return this.list[type]; | ||
} | ||
setState(type, val) { | ||
}; | ||
YEvent.prototype.setState = function (type, val) { | ||
this.list[type] = val; | ||
} | ||
$on(type, cb) { | ||
}; | ||
YEvent.prototype.$on = function (type, cb) { | ||
if (!this.getState(type)) { | ||
this.setState(type, generateDefaultState()); | ||
} | ||
const state = this.getState(type); | ||
var state = this.getState(type); | ||
state.callbacks.push(cb); | ||
if (state.stalled) { | ||
state.stalled = false; | ||
return cb(...state.args); | ||
return cb.apply(void 0, state.args); | ||
} | ||
} | ||
$emit(type, ...args) { | ||
const state = this.getState(type); | ||
}; | ||
YEvent.prototype.$emit = function (type) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
var state = this.getState(type); | ||
if (!state) | ||
return; | ||
state.callbacks.forEach(cb => cb(...args)); | ||
} | ||
$off(type, cb) { | ||
state.callbacks.forEach(function (cb) { return cb.apply(void 0, args); }); | ||
}; | ||
YEvent.prototype.$off = function (type, cb) { | ||
if (!cb) { | ||
@@ -41,13 +45,17 @@ delete this.list[type]; | ||
else { | ||
const cbs = this.list[type].callbacks; | ||
this.list[type].callbacks = cbs.filter(callback => callback !== cb); | ||
var cbs = this.list[type].callbacks; | ||
this.list[type].callbacks = cbs.filter(function (callback) { return callback !== cb; }); | ||
} | ||
} | ||
$always(type, ...args) { | ||
const state = this.getState(type); | ||
}; | ||
YEvent.prototype.$always = function (type) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
var state = this.getState(type); | ||
if (!state) { | ||
this.list[type] = generateDefaultState(); | ||
const state = this.getState(type); | ||
state.stalled = true; | ||
state.args = args; | ||
var state_1 = this.getState(type); | ||
state_1.stalled = true; | ||
state_1.args = args; | ||
return; | ||
@@ -57,14 +65,20 @@ } | ||
return; | ||
state.callbacks.forEach(cb => cb(...args)); | ||
} | ||
$once(type, cb) { | ||
let called = false; | ||
let fn = function (...args) { | ||
!called && cb(...args); | ||
state.callbacks.forEach(function (cb) { return cb.apply(void 0, args); }); | ||
}; | ||
YEvent.prototype.$once = function (type, cb) { | ||
var called = false; | ||
var fn = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
!called && cb.apply(void 0, args); | ||
called = true; | ||
}; | ||
this.$on(type, fn); | ||
} | ||
} | ||
const e = new YEvent(); | ||
}; | ||
return YEvent; | ||
}()); | ||
export { YEvent }; | ||
var e = new YEvent(); | ||
export default e; |
{ | ||
"name": "y-event", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Event system", | ||
@@ -15,4 +15,7 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"start": "tsc" | ||
"watch": "tsc -w", | ||
"buildes": "tsc", | ||
"buildold": "tsc -p tsconfig.old.json", | ||
"build": "npm run buildes && npm run buildold" | ||
} | ||
} |
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"target": "es5", | ||
"module": "es6", | ||
@@ -8,4 +8,3 @@ "lib": ["es2017", "dom"], | ||
"outDir": "lib", | ||
"declaration": true, | ||
"watch": true | ||
"declaration": true | ||
}, | ||
@@ -12,0 +11,0 @@ "include": [ |
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
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
11749
11
324