decko

WebJar for decko

Лицензия

Лицензия

MIT
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

decko
Последняя версия

Последняя версия

1.2.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

decko
WebJar for decko
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/developit/decko

Скачать decko

Имя Файла Размер
decko-1.2.0.pom
decko-1.2.0.jar 10 KB
decko-1.2.0-sources.jar 22 bytes
decko-1.2.0-javadoc.jar 22 bytes
Обзор

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/decko/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>decko</artifactId>
    <version>1.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/decko/
implementation 'org.webjars.npm:decko:1.2.0'
// https://jarcasting.com/artifacts/org.webjars.npm/decko/
implementation ("org.webjars.npm:decko:1.2.0")
'org.webjars.npm:decko:jar:1.2.0'
<dependency org="org.webjars.npm" name="decko" rev="1.2.0">
  <artifact name="decko" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='decko', version='1.2.0')
)
libraryDependencies += "org.webjars.npm" % "decko" % "1.2.0"
[org.webjars.npm/decko "1.2.0"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

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

Версии библиотеки

Версия
1.2.0