This repository has been archived by the owner on May 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtime.js
70 lines (65 loc) · 1.63 KB
/
runtime.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
66
67
68
69
70
export * from './lib/block';
export * from './lib/iterate';
export * from './lib/key-iterate';
export * from './lib/injector';
export * from './lib/scope';
export * from './lib/attribute';
export * from './lib/event';
export * from './lib/slot';
export * from './lib/ref';
export * from './lib/component';
export * from './lib/inner-html';
export * from './lib/dom';
export * from './lib/partial';
export * from './lib/store';
export * from './lib/animation';
export { addDisposeCallback, assign } from './lib/utils';
/**
* Safe property getter
* @param {*} ctx
* @param {*} ...args
* @returns {*}
*/
export function get(ctx) {
const hasMap = typeof Map !== 'undefined';
for (let i = 1, il = arguments.length, arg; ctx != null && i < il; i++) {
arg = arguments[i];
if (hasMap && ctx instanceof Map) {
ctx = ctx.get(arg);
} else {
ctx = ctx[arg];
}
}
return ctx;
}
/**
* Filter items from given collection that matches `fn` criteria and returns
* matched items
* @param {Component} host
* @param {Iterable} collection
* @param {Function} fn
* @returns {Array}
*/
export function filter(host, collection, fn) {
const result = [];
if (collection && collection.forEach) {
collection.forEach((value, key) => {
if (fn(host, value, key)) {
result.push(value);
}
});
}
return result;
}
/**
* Invokes `methodName` of `ctx` object with given args
* @param {Object} ctx
* @param {string} methodName
* @param {Array} [args]
*/
export function call(ctx, methodName, args) {
const method = ctx != null && ctx[methodName];
if (typeof method === 'function') {
return args ? method.apply(ctx, args) : method.call(ctx);
}
}