angular-es-utils
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -23,3 +23,3 @@ 'use strict'; | ||
var fn = target[name]; | ||
var fn = descriptor.value || target[name]; | ||
@@ -26,0 +26,0 @@ // 定义访问器属性的同时不能定义value跟writable |
@@ -20,26 +20,18 @@ 'use strict'; | ||
delete descriptor.value; | ||
delete descriptor.writable; | ||
var fn = target[name]; | ||
var fn = descriptor.value || target[name]; | ||
var timer = null; | ||
descriptor.set = function (value) { | ||
target[name] = value; | ||
}; | ||
descriptor.get = function () { | ||
descriptor.value = function () { | ||
var _this = this; | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
window.clearTimeout(timer); | ||
timer = window.setTimeout(function () { | ||
timer = null; | ||
fn.apply(_this, args); | ||
}, delay); | ||
}; | ||
clearTimeout(timer); | ||
timer = setTimeout(function () { | ||
timer = null; | ||
fn.apply(_this, args); | ||
}, delay); | ||
}; | ||
@@ -46,0 +38,0 @@ |
@@ -20,16 +20,11 @@ 'use strict'; | ||
delete descriptor.value; | ||
delete descriptor.writable; | ||
var fn = descriptor.value || target[name]; | ||
var fn = target[name]; | ||
var recent = void 0; | ||
descriptor.set = function (value) { | ||
target[name] = value; | ||
}; | ||
descriptor.value = function () { | ||
descriptor.get = function () { | ||
var _this = this; | ||
var now = Date.now(); | ||
return function () { | ||
if (!recent || now - recent > delay) { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -39,9 +34,5 @@ args[_key] = arguments[_key]; | ||
var now = Date.now(); | ||
if (!recent || now - recent > delay) { | ||
fn.apply(_this, args); | ||
recent = now; | ||
} | ||
}; | ||
fn.apply(this, args); | ||
recent = now; | ||
} | ||
}; | ||
@@ -48,0 +39,0 @@ |
@@ -33,7 +33,10 @@ 'use strict'; | ||
Object.getOwnPropertyNames(Constructor.prototype).forEach(function (prop) { | ||
var prototype = Object.getPrototypeOf(instance); | ||
Object.getOwnPropertyNames(prototype).forEach(function (prop) { | ||
// 绑定实例到构造函数的每个方法下 | ||
if (prop !== 'constructor' && typeof Constructor.prototype[prop] === 'function') { | ||
instance[prop] = instance[prop].bind(instance); | ||
var fn = prototype[prop]; | ||
if (prop !== 'constructor' && typeof fn === 'function') { | ||
prototype[prop] = fn.bind(instance); | ||
} | ||
@@ -40,0 +43,0 @@ }); |
{ | ||
"name": "angular-es-utils", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "es utils design for angular1.x", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -39,10 +39,2 @@ /** | ||
test('bind decorator', t => { | ||
const test = new Test(); | ||
const getName = test.getName; | ||
t.is(getName(), 'kuitos'); | ||
}); | ||
test('inject decorator', t => { | ||
@@ -56,5 +48,14 @@ | ||
t.is(ctrl.name, 'kuitos'); | ||
t.is(ctrl.getName(), 'kuitos'); | ||
}); | ||
test('bind decorator', t => { | ||
const test = new Test(); | ||
const getName = test.getName; | ||
t.is(getName(), 'kuitos'); | ||
}); | ||
test('throttle decorator', t => { | ||
@@ -61,0 +62,0 @@ |
@@ -17,3 +17,3 @@ /** | ||
const fn = target[name]; | ||
const fn = descriptor.value || target[name]; | ||
@@ -20,0 +20,0 @@ // 定义访问器属性的同时不能定义value跟writable |
@@ -13,21 +13,13 @@ /** | ||
delete descriptor.value; | ||
delete descriptor.writable; | ||
const fn = target[name]; | ||
const fn = descriptor.value || target[name]; | ||
let timer = null; | ||
descriptor.set = value => { | ||
target[name] = value; | ||
}; | ||
descriptor.value = function(...args) { | ||
descriptor.get = function() { | ||
clearTimeout(timer); | ||
return (...args) => { | ||
window.clearTimeout(timer); | ||
timer = window.setTimeout(() => { | ||
timer = null; | ||
fn.apply(this, args); | ||
}, delay); | ||
}; | ||
timer = setTimeout(() => { | ||
timer = null; | ||
fn.apply(this, args); | ||
}, delay); | ||
}; | ||
@@ -34,0 +26,0 @@ |
@@ -13,22 +13,14 @@ /** | ||
delete descriptor.value; | ||
delete descriptor.writable; | ||
const fn = descriptor.value || target[name]; | ||
const fn = target[name]; | ||
let recent; | ||
descriptor.set = value => { | ||
target[name] = value; | ||
}; | ||
descriptor.value = function(...args) { | ||
descriptor.get = function() { | ||
const now = Date.now(); | ||
return (...args) => { | ||
const now = Date.now(); | ||
if (!recent || (now - recent > delay)) { | ||
fn.apply(this, args); | ||
recent = now; | ||
} | ||
}; | ||
if (!recent || (now - recent > delay)) { | ||
fn.apply(this, args); | ||
recent = now; | ||
} | ||
}; | ||
@@ -35,0 +27,0 @@ |
@@ -15,7 +15,10 @@ /** | ||
Object.getOwnPropertyNames(Constructor.prototype).forEach(prop => { | ||
const prototype = Object.getPrototypeOf(instance); | ||
Object.getOwnPropertyNames(prototype).forEach(prop => { | ||
// 绑定实例到构造函数的每个方法下 | ||
if (prop !== 'constructor' && typeof Constructor.prototype[prop] === 'function') { | ||
instance[prop] = instance[prop].bind(instance); | ||
let fn = prototype[prop]; | ||
if (prop !== 'constructor' && typeof fn === 'function') { | ||
prototype[prop] = fn.bind(instance); | ||
} | ||
@@ -31,5 +34,4 @@ | ||
return factory; | ||
} | ||
} |
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
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
261084
45
786