summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilson Page <wilsonpage@me.com>2016-01-05 17:18:23 +0000
committerWilson Page <wilsonpage@me.com>2016-01-05 17:18:23 +0000
commit643469a572934cafb068163638be001eebfe767c (patch)
tree15a7c0ef16452549668be91a3f46dfde3204acaa
parentbd0aa0e1e18f4091a8fe5196e94feaed34e26b36 (diff)
downloadfastdom-origin/73-object-assign.zip
fastdom-origin/73-object-assign.tar.gz
fastdom-origin/73-object-assign.tar.bz2
Replaced Object.assign() with custom mixin()origin/73-object-assign
-rw-r--r--fastdom.js20
-rw-r--r--fastdom.min.js2
-rw-r--r--test/fastdom-test.js8
3 files changed, 24 insertions, 6 deletions
diff --git a/fastdom.js b/fastdom.js
index 919ac4f..dff794b 100644
--- a/fastdom.js
+++ b/fastdom.js
@@ -106,9 +106,8 @@ FastDom.prototype = {
* @example
*
* var myFastdom = fastdom.extend({
- * // called on creation
* initialize: function() {
- *
+ * // runs on creation
* },
*
* // override a method
@@ -130,7 +129,7 @@ FastDom.prototype = {
if (typeof props != 'object') throw new Error('expected object');
var child = Object.create(this);
- Object.assign(child, props);
+ mixin(child, props);
child.fastdom = this;
// run optional creation hook
@@ -151,7 +150,6 @@ FastDom.prototype = {
*
* @private
*/
-
function scheduleFlush(fastdom) {
if (!fastdom.scheduled) {
fastdom.scheduled = true;
@@ -203,7 +201,6 @@ function flush(fastdom) {
*
* @private
*/
-
function runTasks(tasks) {
debug('run tasks');
var task; while (task = tasks.shift()) task.fn.call(task.ctx);
@@ -221,6 +218,19 @@ function remove(array, item) {
return !!~index && !!array.splice(index, 1);
}
+/**
+ * Mixin own properties of source
+ * object into the target.
+ *
+ * @param {Object} target
+ * @param {Object} source
+ */
+function mixin(target, source) {
+ for (var key in source) {
+ if (source.hasOwnProperty(key)) target[key] = source[key];
+ }
+}
+
// There should never be more than
// one instance of `FastDom` in an app
var exports = win.fastdom = (win.fastdom || new FastDom()); // jshint ignore:line
diff --git a/fastdom.min.js b/fastdom.min.js
index 66bd2f1..bf2a555 100644
--- a/fastdom.min.js
+++ b/fastdom.min.js
@@ -1 +1 @@
-!function(t){"use strict";function e(){var e=this;e.reads=[],e.writes=[],e.raf=o.bind(t)}function n(t){t.scheduled||(t.scheduled=!0,t.raf(i.bind(null,t)))}function i(t){var e,i=t.writes,s=t.reads;try{r(s),r(i)}catch(o){e=o}if(t.scheduled=!1,(s.length||i.length)&&n(t),e){if(!t["catch"])throw e;t["catch"](e)}}function r(t){for(var e;e=t.shift();)e.fn.call(e.ctx)}function s(t,e){var n=t.indexOf(e);return!!~n&&!!t.splice(n,1)}var o=t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.msRequestAnimationFrame||function(t){return setTimeout(t,16)};e.prototype={constructor:e,measure:function(t,e){var i={fn:t,ctx:e};return this.reads.push(i),n(this),i},mutate:function(t,e){var i={fn:t,ctx:e};return this.writes.push(i),n(this),i},clear:function(t){return s(this.reads,t)||s(this.writes,t)},extend:function(t){if("object"!=typeof t)throw new Error("expected object");var e=Object.create(this);return Object.assign(e,t),e.fastdom=this,e.initialize&&e.initialize(),e},"catch":null};var exports=t.fastdom=t.fastdom||new e;"f"==(typeof define)[0]?define(function(){return exports}):"o"==(typeof module)[0]&&(module.exports=exports)}(window);
+!function(t){"use strict";function e(){var e=this;e.reads=[],e.writes=[],e.raf=s.bind(t)}function n(t){t.scheduled||(t.scheduled=!0,t.raf(i.bind(null,t)))}function i(t){var e,i=t.writes,o=t.reads;try{r(o),r(i)}catch(a){e=a}if(t.scheduled=!1,(o.length||i.length)&&n(t),e){if(!t["catch"])throw e;t["catch"](e)}}function r(t){for(var e;e=t.shift();)e.fn.call(e.ctx)}function o(t,e){var n=t.indexOf(e);return!!~n&&!!t.splice(n,1)}function a(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])}var s=t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.msRequestAnimationFrame||function(t){return setTimeout(t,16)};e.prototype={constructor:e,measure:function(t,e){var i={fn:t,ctx:e};return this.reads.push(i),n(this),i},mutate:function(t,e){var i={fn:t,ctx:e};return this.writes.push(i),n(this),i},clear:function(t){return o(this.reads,t)||o(this.writes,t)},extend:function(t){if("object"!=typeof t)throw new Error("expected object");var e=Object.create(this);return a(e,t),e.fastdom=this,e.initialize&&e.initialize(),e},"catch":null};var exports=t.fastdom=t.fastdom||new e;"f"==(typeof define)[0]?define(function(){return exports}):"o"==(typeof module)[0]&&(module.exports=exports)}(window);
diff --git a/test/fastdom-test.js b/test/fastdom-test.js
index f28dff6..64f72e5 100644
--- a/test/fastdom-test.js
+++ b/test/fastdom-test.js
@@ -385,5 +385,13 @@ suite('fastdom', function() {
fastdom.extend(999);
});
});
+
+ test('it only mixes in own properties', function() {
+ var proto = { foo: 'foo' };
+ var extension = Object.create(proto);
+ var extended = fastdom.extend(extension);
+
+ assert.isUndefined(extended.foo);
+ });
});
});