Skip to content

Commit

Permalink
If a mutator has no return value (i.e., returns undefined), leave t…
Browse files Browse the repository at this point in the history
…he subject unchanged (useful for in-place updates)
  • Loading branch information
developit committed Mar 11, 2016
1 parent 5545156 commit 0d457c9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/create-cycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export default function createCycle(renderer, data={}) {
// optionally key-specific mutation of data
// eg: mutate('value', v => v*2 )
function mutate(fn, ...args) {
let key;
let key, r;
if (typeof fn==='string') {
key = fn;
fn = args.splice(0, 1)[0];
}
let p = key ? data[key] : data;
if (typeof fn==='function') p = fn(p, ...args);
else p = fn;
if (typeof fn!=='function') p = fn;
else if ( (r=fn(p, ...args))!==undefined ) p = r;
if (key) data[key] = p;
else data = p;
if (!debounce) debounce = setTimeout(render, 1);
Expand Down

0 comments on commit 0d457c9

Please sign in to comment.