Skip to content

Commit

Permalink
drop DOM.register and use internal function instead
Browse files Browse the repository at this point in the history
  • Loading branch information
chemerisuk committed Jan 24, 2015
1 parent cb1222d commit 625c5ce
Show file tree
Hide file tree
Showing 28 changed files with 89 additions and 87 deletions.
18 changes: 0 additions & 18 deletions src/const.js
Expand Up @@ -28,21 +28,3 @@ export const DOM = new $Document(DOCUMENT);
* @namespace DOM
* @extends {$Document}
*/

DOM.register = function(mixins, factory, defaultFactory) {
var proto = defaultFactory ? $Element.prototype : $Document.prototype;

if (factory == null) {
factory = (methodName, strategy) => strategy;
}

keys(mixins).forEach((methodName) => {
var args = [methodName].concat(mixins[methodName]);

proto[methodName] = factory.apply(null, args);

if (defaultFactory) {
$NullElement.prototype[methodName] = defaultFactory.apply(null, args);
}
});
};
3 changes: 2 additions & 1 deletion src/document/create.js
@@ -1,8 +1,9 @@
import { DOM } from "../const";
import { $Element } from "../types";
import tagCache from "../global/emmet";
import { register } from "../util/index";

DOM.register({
register({
/**
* Create a new {@link $Element} from Emmet or HTML string
* @memberof $Document#
Expand Down
4 changes: 2 additions & 2 deletions src/document/extend.js
@@ -1,4 +1,4 @@
import { filter, each } from "../util/index";
import { register, filter, each } from "../util/index";
import { $Element, $Document } from "../types";
import { DOM, JSCRIPT_VERSION, WEBKIT_PREFIX, WINDOW, DOCUMENT, CUSTOM_EVENT_TYPE, RETURN_FALSE, RETURN_TRUE } from "../const";
import { StaticMethodError } from "../errors";
Expand All @@ -23,7 +23,7 @@ if (JSCRIPT_VERSION < 10) {
cssText += WEBKIT_PREFIX + "animation-duration:1ms !important";
}

DOM.register({
register({
/**
* Declare a live extension
* @memberof $Document#
Expand Down
5 changes: 2 additions & 3 deletions src/document/importscripts.js
@@ -1,9 +1,8 @@
import _ from "../util/index";
import { injectElement } from "../util/index";
import { register, injectElement } from "../util/index";
import { DOM } from "../const";
import { StaticMethodError } from "../errors";

DOM.register({
register({
/**
* Import external scripts on the page and call optional callback when it will be done
* @memberof $Document#
Expand Down
4 changes: 2 additions & 2 deletions src/document/importstyles.js
@@ -1,9 +1,9 @@
import _ from "../util/index";
import { register } from "../util/index";
import { injectElement } from "../util/index";
import { DOM } from "../const";
import { StaticMethodError } from "../errors";

DOM.register({
register({
/**
* Append global css styles
* @memberof $Document#
Expand Down
7 changes: 3 additions & 4 deletions src/document/mock.js
@@ -1,8 +1,7 @@
import { each } from "../util/index";
import { register, each } from "../util/index";
import { $NullElement } from "../types";
import { DOM } from "../const";

DOM.register({
register({
/**
* Return {@link $Element} initialized with all existing live extensions.
* Also exposes private functions that do not usually exist. Accepts the
Expand All @@ -17,7 +16,7 @@ DOM.register({
mock(content, varMap) {
if (!content) return new $NullElement();

var result = DOM.create(content, varMap),
var result = this.create(content, varMap),
mappings = this._["<%= prop('mappings') %>"],
applyExtensions = (node) => {
mappings.forEach((ext) => { ext(node, true) });
Expand Down
4 changes: 2 additions & 2 deletions src/element/children.js
@@ -1,10 +1,10 @@
import { filter, map } from "../util/index";
import { register, filter, map } from "../util/index";
import { MethodError } from "../errors";
import { DOM, JSCRIPT_VERSION } from "../const";
import { $Element, $NullElement } from "../types";
import SelectorMatcher from "../util/selectormatcher";

DOM.register({
register({
/**
* Return child element by index filtered by optional selector
* @memberof! $Element#
Expand Down
4 changes: 2 additions & 2 deletions src/element/classes.js
@@ -1,12 +1,12 @@
import _ from "../util/index";
import { register } from "../util/index";
import { DOM, HTML, RETURN_FALSE, RETURN_THIS } from "../const";
import { MethodError } from "../errors";

/* es6-transpiler has-iterators:false, has-generators: false */

var reSpace = /[\n\t\r]/g;

DOM.register({
register({
/**
* Check if element contains class name
* @memberof! $Element#
Expand Down
4 changes: 2 additions & 2 deletions src/element/clone.js
@@ -1,9 +1,9 @@
import _ from "../util/index";
import { register } from "../util/index";
import { MethodError } from "../errors";
import { DOM, JSCRIPT_VERSION } from "../const";
import { $Element, $NullElement } from "../types";

DOM.register({
register({
/**
* Clone element
* @memberof! $Element#
Expand Down
6 changes: 3 additions & 3 deletions src/element/contains.js
@@ -1,9 +1,9 @@
import _ from "../util/index";
import { register } from "../util/index";
import { MethodError } from "../errors";
import { $Element } from "../types";
import { DOM, RETURN_FALSE } from "../const";
import { RETURN_FALSE } from "../const";

DOM.register({
register({
/**
* Check if element is inside of context
* @memberof! $Element#
Expand Down
5 changes: 2 additions & 3 deletions src/element/css.js
@@ -1,9 +1,8 @@
import { keys, isArray, computeStyle } from "../util/index";
import { DOM } from "../const";
import { register, keys, isArray, computeStyle } from "../util/index";
import { MethodError } from "../errors";
import HOOK from "../util/stylehooks";

DOM.register({
register({
/**
* CSS properties accessor for an element
* @memberof! $Element#
Expand Down
6 changes: 3 additions & 3 deletions src/element/define.js
@@ -1,10 +1,10 @@
import _ from "../util/index";
import { register } from "../util/index";
import { MethodError } from "../errors";
import { DOM, JSCRIPT_VERSION, RETURN_THIS } from "../const";
import { JSCRIPT_VERSION, RETURN_THIS } from "../const";

const ATTR_CASE = JSCRIPT_VERSION < 9 ? "toUpperCase" : "toLowerCase";

DOM.register({
register({
/**
* Define a new attribute for the current element
* @memberof! $Element#
Expand Down
5 changes: 3 additions & 2 deletions src/element/empty.js
@@ -1,6 +1,7 @@
import { DOM, RETURN_THIS } from "../const";
import { register } from "../util/index";
import { RETURN_THIS } from "../const";

DOM.register({
register({
/**
* Remove child nodes of current element from the DOM
* @memberof! $Element#
Expand Down
6 changes: 3 additions & 3 deletions src/element/find.js
@@ -1,5 +1,5 @@
import { map, safeCall } from "../util/index";
import { DOM, DOCUMENT } from "../const";
import { register, map, safeCall } from "../util/index";
import { DOCUMENT } from "../const";
import { MethodError } from "../errors";
import { $Element, $NullElement } from "../types";

Expand All @@ -9,7 +9,7 @@ import { $Element, $NullElement } from "../types";
var rquick = DOCUMENT.getElementsByClassName ? /^(?:(\w+)|\.([\w\-]+))$/ : /^(?:(\w+))$/,
rescape = /'|\\/g;

DOM.register({
register({
/**
* Find the first matched element by css selector
* @memberof! $Element#
Expand Down
5 changes: 2 additions & 3 deletions src/element/fire.js
@@ -1,11 +1,10 @@
import _ from "../util/index";
import { safeCall } from "../util/index";
import { register, safeCall } from "../util/index";
import { MethodError } from "../errors";
import { DOM, JSCRIPT_VERSION, CUSTOM_EVENT_TYPE, RETURN_TRUE } from "../const";
import EventHandler from "../util/eventhandler";
import HOOK from "../util/eventhooks";

DOM.register({
register({
/**
* Triggers an event of specific type with optional extra arguments
* @memberof! $Element#
Expand Down
4 changes: 2 additions & 2 deletions src/element/get.js
@@ -1,4 +1,4 @@
import { isArray } from "../util/index";
import { register, isArray } from "../util/index";
import { MethodError } from "../errors";
import PROP from "../util/accessorhooks";
import { DOM } from "../const";
Expand All @@ -24,7 +24,7 @@ var reUpper = /[A-Z]/g,
return value;
};

DOM.register({
register({
/**
* Get property or attribute value by name
* @memberof! $Element#
Expand Down
4 changes: 2 additions & 2 deletions src/element/manipulation.js
@@ -1,8 +1,8 @@
import { isArray } from "../util/index";
import { register, isArray } from "../util/index";
import { DOM, RETURN_THIS } from "../const";
import { $Element } from "../types";

DOM.register({
register({
/**
* Insert HTMLString or {@link $Element} after the current element
* @memberof! $Element#
Expand Down
4 changes: 2 additions & 2 deletions src/element/map.js
@@ -1,7 +1,7 @@
import { DOM } from "../const";
import { register } from "../util/index";
import { MethodError } from "../errors";

DOM.register({
register({
/**
* Invokes a function for element if it's not empty and return array of results
* @memberof! $Element#
Expand Down
6 changes: 3 additions & 3 deletions src/element/matches.js
@@ -1,10 +1,10 @@
import _ from "../util/index";
import { DOM, RETURN_FALSE } from "../const";
import { register } from "../util/index";
import { RETURN_FALSE } from "../const";
import { MethodError } from "../errors";
import SelectorMatcher from "../util/selectormatcher";
import HOOK from "../util/selectorhooks";

DOM.register({
register({
/**
* Check if the element matches selector
* @memberof! $Element#
Expand Down
6 changes: 3 additions & 3 deletions src/element/off.js
@@ -1,8 +1,8 @@
import _ from "../util/index";
import { register } from "../util/index";
import { MethodError } from "../errors";
import { DOM, JSCRIPT_VERSION, RETURN_THIS } from "../const";
import { JSCRIPT_VERSION, RETURN_THIS } from "../const";

DOM.register({
register({
/**
* Unbind an event from the element
* @memberof! $Element#
Expand Down
8 changes: 5 additions & 3 deletions src/element/offset.js
@@ -1,7 +1,7 @@
import _ from "../util/index";
import { register } from "../util/index";
import { DOM, WINDOW } from "../const";

DOM.register({
register({
/**
* Calculates offset of the current element
* @memberof! $Element#
Expand All @@ -28,4 +28,6 @@ DOM.register({
height: boundingRect.bottom - boundingRect.top
};
}
}, null, () => function() { return { top: 0, left: 0, right: 0, bottom: 0, width: 0, height: 0 } });
}, null, () => function() {
return { top: 0, left: 0, right: 0, bottom: 0, width: 0, height: 0 };
});
4 changes: 2 additions & 2 deletions src/element/on.js
@@ -1,9 +1,9 @@
import { isArray, keys } from "../util/index";
import { register, isArray, keys } from "../util/index";
import { MethodError } from "../errors";
import { DOM, JSCRIPT_VERSION, RETURN_THIS } from "../const";
import EventHandler from "../util/eventhandler";

DOM.register({
register({
/**
* Bind a DOM event
* @memberof! $Element#
Expand Down
4 changes: 2 additions & 2 deletions src/element/set.js
@@ -1,10 +1,10 @@
import { isArray, keys } from "../util/index";
import { register, isArray, keys } from "../util/index";
import { safeCall } from "../util/index";
import { MethodError } from "../errors";
import { DOM, JSCRIPT_VERSION, LEGACY_ANDROID, RETURN_THIS } from "../const";
import PROP from "../util/accessorhooks";

DOM.register({
register({
/**
* Set property/attribute value by name
* @memberof! $Element#
Expand Down
4 changes: 2 additions & 2 deletions src/element/traversing.js
@@ -1,10 +1,10 @@
import { map } from "../util/index";
import { register, map } from "../util/index";
import { DOM } from "../const";
import { MethodError } from "../errors";
import { $Element, $NullElement } from "../types";
import SelectorMatcher from "../util/selectormatcher";

DOM.register({
register({
/**
* Find next sibling element filtered by optional selector
* @memberof! $Element#
Expand Down
4 changes: 2 additions & 2 deletions src/element/value.js
@@ -1,8 +1,8 @@
import { every } from "../util/index";
import { register, every } from "../util/index";
import { DOM, JSCRIPT_VERSION, RETURN_THIS } from "../const";
import { $Element } from "../types";

DOM.register({
register({
/**
* Read or write inner content of the element
* @memberof! $Element#
Expand Down
4 changes: 2 additions & 2 deletions src/element/visibility.js
@@ -1,12 +1,12 @@
import { computeStyle } from "../util/index";
import { register, computeStyle } from "../util/index";
import { MethodError } from "../errors";
import { DOM, WEBKIT_PREFIX, RETURN_THIS } from "../const";
import AnimationHandler from "../util/animationhandler";

var TRANSITION_EVENT_TYPE = WEBKIT_PREFIX ? "webkitTransitionEnd" : "transitionend",
ANIMATION_EVENT_TYPE = WEBKIT_PREFIX ? "webkitAnimationEnd" : "animationend";

DOM.register({
register({
/**
* Show an element using CSS3 transition or animation
* @memberof! $Element#
Expand Down
5 changes: 3 additions & 2 deletions src/element/watch.js
@@ -1,6 +1,7 @@
import { DOM, RETURN_THIS } from "../const";
import { register } from "../util/index";
import { RETURN_THIS } from "../const";

DOM.register({
register({
/**
* Watch for changes of a particular property/attribute
* @memberof! $Element#
Expand Down

0 comments on commit 625c5ce

Please sign in to comment.