diff options
Diffstat (limited to 'src/fastdom-strict.js')
-rw-r--r-- | src/fastdom-strict.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/fastdom-strict.js b/src/fastdom-strict.js new file mode 100644 index 0000000..86d3f4e --- /dev/null +++ b/src/fastdom-strict.js @@ -0,0 +1,49 @@ +'use strict'; + +var strictdom = require('strictdom'); +var fastdom = require('../fastdom'); + +/** + * Mini logger + * + * @return {Function} + */ +var debug = 0 ? console.log.bind(console, '[fastdom-strict]') : function() {}; + +/** + * Enabled state + * + * @type {Boolean} + */ +var enabled = false; + +window.fastdom = module.exports = fastdom.extend({ + measure: function(task, ctx) { + debug('measure'); + return this.fastdom.measure(function() { + if (!enabled) return task(); + return strictdom.phase('measure', task); + }, ctx); + }, + + mutate: function(task, ctx) { + debug('mutate'); + return this.fastdom.mutate(function() { + if (!enabled) return task(); + return strictdom.phase('mutate', task); + }, ctx); + }, + + strict: function(value) { + if (value) { + enabled = true; + strictdom.enable(); + } else { + enabled = false; + strictdom.disable(); + } + } +}); + +// turn on strict-mode +window.fastdom.strict(true); |