-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
65 lines (57 loc) · 1.61 KB
/
index.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// UMD for plugins
// https://github.com/umdjs/umd/blob/master/README.md
// https://github.com/umdjs/umd/blob/master/jqueryPluginCommonjs.js
( function umd( factory ){
if( typeof define === 'function' && define.amd ){
define( [ 'mithril' ], factory)
}
else if( typeof exports === 'object' ){
module.exports = factory( require( 'mithril' ) )
}
else {
factory( m )
}
}( function factory( m ){
// Assign all properties of subsequent arguments to the first
function assign( target ){
for( var i = 1, l = arguments.length; i < l; i++ )
for( var key in arguments[ i ] )
if( arguments[ i ].hasOwnProperty( key ) )
target[ key ] = arguments[ i ][ key ]
}
// Pass virtual DOM node through each of the available transformations in node.attrs
function transform( node, transformations ){
for( var key in node.attrs )
if( transformations.hasOwnProperty( node.attrs[ key ] ) ){
var transformed = transformations[ key ](
node,
node.attrs[ key ],
node.attrs
)
if( transformed !== undefined )
node = transformed
}
return node
}
// Core public API: accepts a map of transformations,
// returns an enhanced mithril which processes them
function mattr( transformations ){
transformations = transformations || {}
return assign(
function(){
return transform(
m.apply( undefined, arguments ),
transformations
)
}, m, {
attrs : transformations
} )
}
var attrs = {}
// If you want a globally enhanced mithril, use this.
// Transformations can be assigned via attrs property
build.m = assign( mattr( attr ), {
attrs : attrs
} )
return mattr
} ) )