-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy path_construct-element.js
More file actions
35 lines (29 loc) · 906 Bytes
/
Copy path_construct-element.js
File metadata and controls
35 lines (29 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict';
var copy = require('es5-ext/object/copy')
, forEach = require('es5-ext/object/for-each')
, isPlainObject = require('es5-ext/object/is-plain-object')
, slice = Array.prototype.slice, keys = Object.keys;
module.exports = function (el, args) {
var directives, attrs = args[0];
if (isPlainObject(attrs) && (typeof attrs.toDOM !== 'function')) {
forEach(attrs, function (value, name) {
if (el._directives[name]) {
if (!directives) directives = {};
directives[name] = value;
}
});
if (directives) {
attrs = copy(attrs);
keys(directives).forEach(function (name) { delete attrs[name]; });
args = slice.call(args, 1);
args.unshift(attrs);
}
}
// run constructors
el._construct.apply(el, args);
if (!directives) return;
// Apply directives
forEach(directives, function (value, name) {
el._directives[name].call(el, value);
});
};