shiki-decorators
This repository contains set of useful es7 decorators: bind
, memoize
, chain
, throttle
and debounce
.
@bind
uses NoHomey/bind-decorator
Binds method to the current context.
;// or to import with tree shaking use// import bind from 'shiki-decorators/src/bind'; a = 'a from example' @bind { console; } { console; } const example = ;const z = a: 'a from z' ;zfoo = examplefoo;zboo = exampleboo; z;z; // Output// a from example// a from z
@memoize
uses andreypopp/memoize-decorator
A method/getter decorator which is when applied to a method or a getter memoizes the result of the first call and returns it on subsequent calls.
;// or to import with tree shaking use// import memoize from 'shiki-decorators/src/memoize'; @memoize { console; return 'foo'; } @memoize { console; return 'boo'; } let example = ; console; // prints '', and then prints "1"console; // prints '', and then prints "1" console; // just prints '1'console; // just prints '1' // Output// heavy method computations// foo// heavy getter computations// boo// foo// boo
@chain
Allows chaining execution of a function. Each method returns a called object, allowing the calls to be chained together in a single statement.
;// or to import with tree shaking use// import chain from 'shiki-decorators/src/chain'; @chain { console; } const example = ;example; // Output// num: 1// num: 2
@throttle
Throttle execution of a function. Especially useful for rate limiting execution of handlers on events like resize and scroll.
;// or to import with tree shaking use// import throttle from 'shiki-decorators/src/throttle'; @ { console; } const example = ; example; // Will execute the callbackexample; // Won’t execute callbackexample; // Won’t execute callback ; ; // Output// num: 1// num: 10// num: 100
@debounce
Debounce execution of a function. Debouncing, unlike throttling, guarantees that a function is only executed a single time, either at the very beginning of a series of calls, or at the very end.
;// or to import with tree shaking use// import debounce from 'shiki-decorators/src/debounce'; @ { console; } const example = ; example; // Won't execute callbackexample; // Won’t execute callbackexample; // Will execute the callback ; // Output// num: 3// num: 10
Package release command
GITHUB_TOKEN=... npm run release