Comparing version 0.8.1 to 0.8.2
{ | ||
"name": "fastdom", | ||
"description": "Eliminates layout thrashing by batching DOM read/write operations", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "scripts": [ |
{ | ||
"name": "fastdom", | ||
"description": "Eliminates layout thrashing by batching DOM read/write operations", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "scripts": [ |
0.8.2 / 2013-10-15 | ||
================== | ||
* fix - prevent unnecessary frame being scheduled when write requested inside read callback, inside write callback. | ||
0.8.1 / 2013-10-15 | ||
@@ -10,3 +15,3 @@ ================== | ||
* change - to a rAF loop technique of emtying frame queue to prevent frame conflicts | ||
* change - to a rAF loop technique of emptying frame queue to prevent frame conflicts | ||
* add - ability to call `FastDom#defer` with no frame argument to schedule job for next free frame | ||
@@ -13,0 +18,0 @@ * change - errors not caught by default |
59
index.js
@@ -43,7 +43,7 @@ | ||
this.lastId = 0; | ||
this.mode = null; | ||
this.batch = { | ||
hash: {}, | ||
read: [], | ||
write: [] | ||
write: [], | ||
mode: null | ||
}; | ||
@@ -62,13 +62,20 @@ } | ||
var job = this.add('read', fn, ctx); | ||
var id = job.id; | ||
// Add this job to the read queue | ||
this.batch.read.push(job.id); | ||
// If we're writing and a 'read' job | ||
// comes in, we do have to schedule a new frame | ||
var needsFrame = !this.batchPending || this.mode === 'writing'; | ||
// We should *not* schedule a new frame if: | ||
// 1. We're 'reading' | ||
// 2. A frame is already scheduled | ||
var doesntNeedFrame = this.batch.mode === 'reading' | ||
|| this.batch.scheduled; | ||
// Schedule a new frame if need be | ||
if (needsFrame) this.scheduleBatch(); | ||
// If a frame isn't needed, return | ||
if (doesntNeedFrame) return id; | ||
return job.id; | ||
// Schedule a new | ||
// frame, then return | ||
this.scheduleBatch(); | ||
return id; | ||
}; | ||
@@ -86,17 +93,23 @@ | ||
var job = this.add('write', fn, ctx); | ||
var mode = this.batch.mode; | ||
var id = job.id; | ||
// Push the job id into the queue | ||
this.batch.write.push(job.id); | ||
// If we're emptying the read | ||
// batch and a write comes in, | ||
// we don't need to schedule a | ||
// new frame. If we're writing | ||
// and write comes in we don't | ||
// need to schedule a new frame | ||
var needsFrame = !this.batchPending; | ||
// We should *not* schedule a new frame if: | ||
// 1. We are 'writing' | ||
// 2. We are 'reading' | ||
// 3. A frame is already scheduled. | ||
var doesntNeedFrame = mode === 'writing' | ||
|| mode === 'reading' | ||
|| this.batch.scheduled; | ||
// Schedule a new frame if need be | ||
if (needsFrame) this.scheduleBatch(); | ||
// If a frame isn't needed, return | ||
if (doesntNeedFrame) return id; | ||
return job.id; | ||
// Schedule a new | ||
// frame, then return | ||
this.scheduleBatch(); | ||
return id; | ||
}; | ||
@@ -184,4 +197,4 @@ | ||
this.schedule(0, function() { | ||
self.batch.scheduled = false; | ||
self.runBatch(); | ||
self.batchPending = false; | ||
}); | ||
@@ -191,3 +204,3 @@ | ||
// a frame has been scheduled | ||
this.batchPending = true; | ||
this.batch.scheduled = true; | ||
}; | ||
@@ -235,3 +248,3 @@ | ||
// then empty all read jobs | ||
this.mode = 'reading'; | ||
this.batch.mode = 'reading'; | ||
this.flush(this.batch.read); | ||
@@ -241,6 +254,6 @@ | ||
// then empty all write jobs | ||
this.mode = 'writing'; | ||
this.batch.mode = 'writing'; | ||
this.flush(this.batch.write); | ||
this.mode = null; | ||
this.batch.mode = null; | ||
}; | ||
@@ -247,0 +260,0 @@ |
{ | ||
"name": "fastdom", | ||
"description": "Eliminates layout thrashing by batching DOM read/write operations", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -94,3 +94,3 @@ # fastdom [![Build Status](https://travis-ci.org/wilsonpage/fastdom.png?branch=master)](https://travis-ci.org/wilsonpage/fastdom) | ||
`FastDom#defer` can also be called with no `frames` argument to push work onto next avaiable frame. | ||
`FastDom#defer` can also be called without the `frames` argument to push work onto next available frame. | ||
@@ -110,3 +110,3 @@ ```js | ||
Clears **any** scheduled job by id. | ||
Clears **any** scheduled job. | ||
@@ -123,2 +123,13 @@ ```js | ||
## Exceptions | ||
FastDom is async, this can therefore mean that when a job comes around to being executed, the node you were working with may no longer be there. These errors are usually not critical, but they can cripple your app. FastDom allows you to register an `onError` handler. If `fastdom.onError` has been registered, FastDom will catch any errors that occur in your jobs, and run the handler instead. | ||
```js | ||
fastdom.onError = function(error) { | ||
// Do something if you want | ||
}; | ||
``` | ||
## Tests | ||
@@ -139,7 +150,7 @@ | ||
- **Wilson Page** - [@wilsonpage](http://github.com/wilsonpage) | ||
- **Wilson Page** - [@wilsonpage](http://twitter.com/wilsonpage) | ||
## Contributors | ||
- **Wilson Page** - [@wilsonpage](http://github.com/wilsonpage) | ||
- **Wilson Page** - [@wilsonpage](http://twitter.com/wilsonpage) | ||
- **George Crawford** - [@georgecrawford](http://github.com/georgecrawford) | ||
@@ -146,0 +157,0 @@ |
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
15866
373
165