Skip to content

Commit 13d2566

Browse files
committed
bump
1 parent a820769 commit 13d2566

File tree

5 files changed

+41
-8
lines changed

5 files changed

+41
-8
lines changed

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# ide
22
.komodotools
3+
.vscode
34
*.komodoproject
45

56
.gitignore

lib/memd.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ var _src_deco_debounce;
254254
var module = { exports: exports };
255255
"use strict";
256256
Object.defineProperty(exports, "__esModule", { value: true });
257+
var requestFn = typeof requestAnimationFrame === 'undefined' ? setImmediate : requestAnimationFrame;
258+
var clearRequest = typeof requestAnimationFrame === 'undefined' ? clearImmediate : cancelAnimationFrame;
257259
/**
258260
*
259261
* @param timeout ms to wait before calling inner fn
@@ -277,9 +279,9 @@ function deco_debounce(timeout) {
277279
}
278280
var self = this;
279281
if (frame_1 !== 0) {
280-
cancelAnimationFrame(frame_1);
282+
clearRequest(frame_1);
281283
}
282-
frame_1 = requestAnimationFrame(function () {
284+
frame_1 = requestFn(function () {
283285
frame_1 = 0;
284286
fn.apply(self, args);
285287
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "Alexander Kit",
66
"email": "alex.kit@atmajs.com"
77
},
8-
"version": "0.2.68",
8+
"version": "0.2.69",
99
"main": "./lib/memd.js",
1010
"types": "./lib/memd.d.ts",
1111
"repository": {

readme.md

+31-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33

44
[![Build Status](https://travis-ci.org/atmajs/Ruta.png?branch=master)](https://travis-ci.org/tenbits/memd)
55
[![NPM version](https://badge.fury.io/js/memd.svg)](http://badge.fury.io/js/memd)
6-
[![Bower version](https://badge.fury.io/bo/memd.svg)](http://badge.fury.io/bo/memd)
76

8-
9-
Object Cache. Memoize, debounce, throttle and queue methods.
7+
* Memoize, debounce, throttle and queue methods
8+
* Object Cache
109

1110
```typescript
1211

@@ -52,5 +51,34 @@ const cache = new Cache(<ICacheOpts> { maxAge: 60 });
5251

5352
```
5453

54+
### `memoize`
55+
56+
```ts
57+
.memoize(opts?: ICacheOpts)
58+
```
59+
60+
### `debounce`
61+
62+
When `ms` is `0` or `undefined` then `requestAnimationFrame` or `setImmediate` is used.
63+
64+
```ts
65+
.memoize(ms: number = 0)
66+
```
67+
68+
### `throttle`
69+
70+
```ts
71+
.throttle(ms: number, shouldCallLater?: boolean)
72+
```
73+
74+
### `queued`
75+
76+
Calls method only when the previous promise is resolved. Use `trimQueue: true` to ensure the queue consists of max 1 listener.
77+
78+
```ts
79+
async .queued(opts: { trimQueue?: boolean })
80+
```
81+
5582
----
5683
_Atma.js Project_
84+

src/deco/debounce.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const requestFn: any = typeof requestAnimationFrame === 'undefined' ? setImmediate : requestAnimationFrame;
2+
const clearRequest: any = typeof requestAnimationFrame === 'undefined' ? clearImmediate : cancelAnimationFrame;
13
/**
24
*
35
* @param timeout ms to wait before calling inner fn
@@ -17,9 +19,9 @@ export function deco_debounce (timeout?: number) {
1719
descriptor.value = function (...args) {
1820
const self = this;
1921
if (frame !== 0) {
20-
cancelAnimationFrame(frame);
22+
clearRequest(frame);
2123
}
22-
frame = requestAnimationFrame(function() {
24+
frame = requestFn(function() {
2325
frame = 0;
2426
fn.apply(self, args);
2527
});

0 commit comments

Comments
 (0)