Skip to content

Commit

Permalink
drop _.assign, fix tests in IE8
Browse files Browse the repository at this point in the history
  • Loading branch information
chemerisuk committed Oct 14, 2014
1 parent b9cba3e commit 6d384ad
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/dom/extend.js
@@ -1,7 +1,7 @@
import _ from "../util/index";
import { DOM } from "../types";
import { JSCRIPT_VERSION, WEBKIT_PREFIX, WINDOW, DOCUMENT, CUSTOM_EVENT_TYPE } from "../const";
import { StaticMethodError } from "../errors";
import { $Element, DOM } from "../types";
import ExtensionHandler from "../util/extensionhandler";

// Inspired by trick discovered by Daniel Buchner:
Expand Down
23 changes: 13 additions & 10 deletions src/util/extensionhandler.js
Expand Up @@ -4,8 +4,7 @@ import SelectorMatcher from "../util/selectormatcher";

var rePrivateFunction = /^(?:on|do)[A-Z]/,
ExtensionHandler = (selector, condition, mixins, index) => {
var privateFunctions = _.keys(mixins).filter((prop) => !!rePrivateFunction.exec(prop)),
ctr = mixins.hasOwnProperty("constructor") && mixins.constructor,
var ctr = mixins.hasOwnProperty("constructor") && mixins.constructor,
matcher = SelectorMatcher(selector),
ext = (node, mock) => {
var el = $Element(node);
Expand All @@ -14,20 +13,24 @@ var rePrivateFunction = /^(?:on|do)[A-Z]/,

if (mock === true || condition(el) !== false) {
// apply all private/public members to the interface
_.assign(el, mixins);
// preserve this for private functions
privateFunctions.forEach((prop) => {
var fn = el[prop];
var privateFunctions = Object.keys(mixins).filter(function(prop) {
var method = mixins[prop];

el[prop] = () => fn.apply(el, arguments);
if (rePrivateFunction.exec(prop)) {
// preserve context for private functions
el[prop] = () => method.apply(el, arguments);

return !mock;
}

el[prop] = method;
});

// invoke constructor if it exists
// make a safe call so live extensions can't break each other
if (ctr) _.safeInvoke(el, ctr);
// remove event handlers from element's interface
privateFunctions.forEach((prop) => {
if (mock !== true) delete el[prop];
});
privateFunctions.forEach((prop) => { delete el[prop] });
}
};

Expand Down
7 changes: 0 additions & 7 deletions src/util/index.js
Expand Up @@ -18,13 +18,6 @@ export default {
slice: arrayProto.slice,
isArray: Array.isArray,
keys: Object.keys,
assign: (target, source) => {
Object.keys(source).forEach((key) => {
target[key] = source[key];
});

return target;
},
safeInvoke: (context, fn, arg1, arg2) => {
if (typeof fn === "string") fn = context[fn];

Expand Down
9 changes: 8 additions & 1 deletion test/spec/dom/importstyles.spec.js
Expand Up @@ -19,7 +19,14 @@ describe("DOM.importStyles", function() {
expect(link.css("display")).not.toBe("none");
DOM.importStyles("#importStyles2", {"display": "none", "some-prop": "test"});
expect(link.css("display")).toBe("none");
expect(link.css("some-prop")).toBeUndefined();

var unknownProp = link.css("some-prop");
// different browsers handle unknown properties differently
if (unknownProp) {
expect(unknownProp).toBe("test");
} else {
expect(unknownProp).toBeUndefined();
}
});

it("should handle vendor prefixed properties", function() {
Expand Down

0 comments on commit 6d384ad

Please sign in to comment.