reactive-function
Advanced tools
Comparing version 0.8.0 to 0.8.1
28
index.js
var ReactiveProperty = require("reactive-property"); | ||
var Graph = require("graph-data-structure"); | ||
// Use requestAnimationFrame if it is available. | ||
// Otherwise fall back to setTimeout. | ||
var nextFrame = setTimeout; | ||
if(typeof requestAnimationFrame !== 'undefined') { | ||
nextFrame = requestAnimationFrame; | ||
} | ||
// The singleton data dependency graph. | ||
@@ -58,3 +65,3 @@ // Nodes are reactive properties. | ||
// Assign node ids to inputs and the reactive function. | ||
// Assign node ids to inputs and output. | ||
assignId(output); | ||
@@ -120,11 +127,16 @@ inputs.forEach(assignId); | ||
// Returns a function that, when invoked, schedules the given function | ||
// to execute once on the next tick of the JavaScript event loop. | ||
// to execute once on the next frame. | ||
// Similar to http://underscorejs.org/#debounce | ||
function debounce(fn){ | ||
var timeout; | ||
function debounce(callback){ | ||
var queued = false; | ||
return function () { | ||
clearTimeout(timeout); | ||
timeout = setTimeout(fn) | ||
if(!queued){ | ||
queued = true; | ||
nextFrame(function () { | ||
queued = false; | ||
callback(); | ||
}, 0); | ||
} | ||
}; | ||
}; | ||
} | ||
@@ -143,2 +155,4 @@ // Returns true if all elements of the given array are defined. | ||
ReactiveFunction.nextFrame = nextFrame; | ||
module.exports = ReactiveFunction; |
{ | ||
"name": "reactive-function", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "A library for managing data flows and changing state.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -192,3 +192,3 @@ // Unit tests for reactive-function. | ||
setTimeout(function (){ | ||
ReactiveFunction.nextFrame(function (){ | ||
assert.equal(c(), 15); | ||
@@ -213,3 +213,3 @@ done(); | ||
// Wait until after the first auto-digest. | ||
setTimeout(function (){ | ||
ReactiveFunction.nextFrame(function (){ | ||
@@ -222,3 +222,3 @@ rf.destroy(); | ||
// Give time for an auto-digest to occur. | ||
setTimeout(function (){ | ||
ReactiveFunction.nextFrame(function (){ | ||
@@ -225,0 +225,0 @@ // Confirm that a digest did not occur. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19974
483