Skip to content

Commit f3fedd9

Browse files
committed
Initial commit
0 parents  commit f3fedd9

7 files changed

Lines changed: 174 additions & 0 deletions

File tree

.babelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"modules": "umd",
3+
"loose": "all",
4+
"compact": true,
5+
"comments": false,
6+
"stage": 0
7+
}

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
lib-cov
2+
*.seed
3+
*.log
4+
*.csv
5+
*.dat
6+
*.out
7+
*.pid
8+
*.gz
9+
10+
pids
11+
logs
12+
results
13+
14+
npm-debug.log
15+
node_modules
16+
bower_components

.jshintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"esnext": true,
3+
"browser": true
4+
}

.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
src
2+
bower.json
3+
README.md
4+
.babelrc
5+
.editorconfig
6+
.jshintrc

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Jason Miller
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
decko [![NPM Version](http://img.shields.io/npm/v/decko.svg?style=flat)](https://npmjs.com/package/decko)
2+
=====
3+
4+
> A collection of the most useful [decorators](https://github.com/wycats/javascript-decorators).
5+
6+
7+
Installation
8+
------------
9+
10+
Available on [npm](https://npmjs.com/package/decko):
11+
12+
```sh
13+
npm i -S decko
14+
```
15+
16+
17+
Usage
18+
-----
19+
20+
Each decorator method is available as a named import.
21+
22+
```js
23+
import { bind, memoize, debounce } from 'decko';
24+
```
25+
26+
27+
# `@bind`
28+
29+
```js
30+
class Example {
31+
@bind
32+
foo() {
33+
// the value of `this` is always the object from which foo() was referenced.
34+
return this;
35+
}
36+
}
37+
38+
let e = new Example();
39+
assert.equal(e.foo(), e);
40+
```
41+
42+
43+
44+
# `@memoize`
45+
46+
> Cache values returned from the decorated function.
47+
> Uses the first argument as a cache key.
48+
> _Cache keys are always converted to strings._
49+
>
50+
> ##### Options:
51+
>
52+
> `caseSensitive: false` - _Makes cache keys case-insensitive_
53+
>
54+
> `cache: {}` - _Presupply cache storage, for seeding or sharing entries_
55+
56+
```js
57+
class Example {
58+
@memoize
59+
expensive(key) {
60+
let start = Date.now();
61+
while (Date.now()-start < 500) key++;
62+
return key;
63+
}
64+
}
65+
66+
let e = new Example();
67+
68+
// this takes 500ms
69+
let one = e.expensive(1);
70+
71+
// this takes 0ms
72+
let two = e.expensive(1);
73+
74+
// this takes 500ms
75+
let three = e.expensive(2);
76+
```
77+
78+
79+
80+
# `@debounce`
81+
82+
> Throttle calls to the decorated function. To debounce means "call this at most once per N ms".
83+
> 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.
84+
>
85+
> ##### Options:
86+
>
87+
> `delay: 0` - _The number of milliseconds to buffer calls for._
88+
89+
```js
90+
class Example {
91+
@debounce
92+
foo() {
93+
return this;
94+
}
95+
}
96+
97+
let e = new Example();
98+
99+
// this will only call foo() once:
100+
for (let i=1000; i--) e.foo();
101+
```

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "decko",
3+
"version": "1.0.0",
4+
"main": "decko.js",
5+
"description": "A collection of the most useful property decorators.",
6+
"scripts": {
7+
"build": "babel src --source-root src -s -d .",
8+
"test": "jshint src/**.js",
9+
"prepublish": "npm run build",
10+
"release": "npm run build && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git://github.com/developit/decko.git"
15+
},
16+
"devDependencies": {
17+
"babel": "^5.8.21",
18+
"jshint": "^2.8.0"
19+
}
20+
}

0 commit comments

Comments
 (0)