All Projects â†’ developit â†’ Decko

developit / Decko

Licence: mit
💨 The 3 most useful ES7 decorators: bind, debounce and memoize

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Decko

Cachier
Persistent, stale-free, local and cross-machine caching for Python functions.
Stars: ✭ 359 (-64.94%)
Mutual labels:  decorators, memoization
Memo Decorator
Decorator which applies memoization to a method of a class.
Stars: ✭ 213 (-79.2%)
Mutual labels:  decorators, memoization
Draper
Decorators/View-Models for Rails Applications
Stars: ✭ 5,053 (+393.46%)
Mutual labels:  decorators
Immutable Tuple
Immutable finite list objects with constant-time equality testing (===) and no memory leaks.
Stars: ✭ 29 (-97.17%)
Mutual labels:  memoization
Re Reselect
Enhance Reselect selectors with deeper memoization and cache management.
Stars: ✭ 932 (-8.98%)
Mutual labels:  memoization
Moize
The consistently-fast, complete memoization solution for JS
Stars: ✭ 628 (-38.67%)
Mutual labels:  memoization
Dugong
Minimal State Store Manager for React Apps using RxJS
Stars: ✭ 10 (-99.02%)
Mutual labels:  decorators
Vue Property Decorator
Vue.js and Property Decorator
Stars: ✭ 5,156 (+403.52%)
Mutual labels:  decorators
React Apollo Decorators
Better decorators for Apollo and React
Stars: ✭ 39 (-96.19%)
Mutual labels:  decorators
Active decorator
ORM agnostic truly Object-Oriented view helper for Rails 4, 5, and 6
Stars: ✭ 928 (-9.37%)
Mutual labels:  decorators
Tvrboreact
Dream starter project: React, Redux, React Router, Webpack
Stars: ✭ 13 (-98.73%)
Mutual labels:  decorators
Koa Dec Router
An ES6 decorator + class based router, support inherit, override, priority, auto load controllers, etc.
Stars: ✭ 19 (-98.14%)
Mutual labels:  decorators
React Decoration
A collection of decorators for React Components
Stars: ✭ 641 (-37.4%)
Mutual labels:  decorators
Mongoose Model Decorators
ES2016 decorator functions for building Mongoose models
Stars: ✭ 11 (-98.93%)
Mutual labels:  decorators
Alosaur
Alosaur - Deno web framework with many decorators
Stars: ✭ 559 (-45.41%)
Mutual labels:  decorators
Injection Js
Dependency injection library for JavaScript and TypeScript in 5.1K. It is an extraction of the Angular's ReflectiveInjector which means that it's well designed, feature complete, fast, reliable and well tested.
Stars: ✭ 962 (-6.05%)
Mutual labels:  decorators
Cached
Rust cache structures and easy function memoization
Stars: ✭ 530 (-48.24%)
Mutual labels:  memoization
Type Graphql
Create GraphQL schema and resolvers with TypeScript, using classes and decorators!
Stars: ✭ 6,864 (+570.31%)
Mutual labels:  decorators
Decorum
Tasteful decorators for Ruby.
Stars: ✭ 7 (-99.32%)
Mutual labels:  decorators
Ember Arg Types
Runtime type checking & defaulting for glimmer component arguments powered by prop-types & decorators
Stars: ✭ 43 (-95.8%)
Mutual labels:  decorators

decko NPM Version Build Status

A concise implementation of the three most useful decorators:

  • @bind: make the value of this constant within a method
  • @debounce: throttle calls to a method
  • @memoize: cache return values based on arguments

Decorators help simplify code by replacing the noise of common patterns with declarative annotations. Conversely, decorators can also be overused and create obscurity. Decko establishes 3 standard decorators that are immediately recognizable, so you can avoid creating decorators in your own codebase.

💡 Tip: decko is particularly well-suited to Preact Classful Components.

💫 Note:

Installation

Available on npm:

npm i -S decko

Usage

Each decorator method is available as a named import.

import { bind, memoize, debounce } from 'decko';

@bind

class Example {
	@bind
	foo() {
		// the value of `this` is always the object from which foo() was referenced.
		return this;
	}
}

let e = new Example();
assert.equal(e.foo.call(null), e);

@memoize

Cache values returned from the decorated function. Uses the first argument as a cache key. Cache keys are always converted to strings.

Options:

caseSensitive: false - Makes cache keys case-insensitive

cache: {} - Presupply cache storage, for seeding or sharing entries

class Example {
	@memoize
	expensive(key) {
		let start = Date.now();
		while (Date.now()-start < 500) key++;
		return key;
	}
}

let e = new Example();

// this takes 500ms
let one = e.expensive(1);

// this takes 0ms
let two = e.expensive(1);

// this takes 500ms
let three = e.expensive(2);

@debounce

Throttle calls to the decorated function. To debounce means "call this at most once per N ms". All outward function calls get collated into a single inward call, and only the latest (most recent) arguments as passed on to the debounced function.

Options:

delay: 0 - The number of milliseconds to buffer calls for.

class Example {
	@debounce
	foo() {
		return this;
	}
}

let e = new Example();

// this will only call foo() once:
for (let i=1000; i--) e.foo();

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].