-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathindex.js
More file actions
119 lines (97 loc) · 2.75 KB
/
index.js
File metadata and controls
119 lines (97 loc) · 2.75 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import {require_condition} from './assert'
import * as ReactUtils from './react'
import * as Errors from './errors'
export {require_condition, ReactUtils, Errors}
export function watchPropertyChange(target, property, cb) {
require_condition(
target != null &&
typeof property === 'string' &&
typeof cb === 'function', 'invalid arguments')
let cache = null
if (!target.__watch_cache){
target.__watch_cache = {}
}
cache = target.__watch_cache
require_condition(cache[property] == null, `duplicated watch on ${target} 's ${property}`)
cache[property] = cb
let origin = target[property]
Object.defineProperty(target, property, {
configurable: true,
get() {
return origin
},
set(value) {
origin = value
if (cache[property]){
cache[property](origin)
}
}
})
return ()=>{
if (target.__watch_cache && target.__watch_cache[property]){
delete target.__watch_cache[property]
delete target[property]
target[property] = origin
}
}
}
export function createPropType(validate) {
// Chainable isRequired
function checkType(isRequired, props, propName, componentName) {
componentName = componentName || '<<anonymous>>';
if (props[propName] == null) {
if (isRequired) {
return new Error(
("Required `" + propName + "` was not specified in ") +
("`" + componentName + "`.")
);
}
return null;
} else {
return validate(props, propName, componentName);
}
}
let chainedCheckType = checkType.bind(null, false);
chainedCheckType.isRequired = checkType.bind(null, true);
return chainedCheckType;
}
// take from : http://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/
export function hashCode(str) {
if (str == null||str.length === 0) return 0
let hash = 0;
for (let i = 0; i < str.length; i++) {
let char = str.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash = hash & hash; // Convert to 32bit integer
}
return hash;
}
export function pick(obj, keys) {
require_condition(obj != null && Array.isArray(keys))
const r = {}
keys.forEach(e=> r[e]= obj[e])
return r
}
export function range(start, stop, step) {
if (stop == null) {
stop = start || 0;
start = 0;
}
if (!step) {
step = stop < start ? -1 : 1;
}
var length = Math.max(Math.ceil((stop - start) / step), 0);
var range = Array(length);
for (var idx = 0; idx < length; idx++, start += step) {
range[idx] = start;
}
return range;
}
export {default as DateUtils} from './date'
export {IDGenerator} from './IDGenerator'
const popperMixins =
typeof window === "undefined" ? {} : require("./popper-mixins")
module.exports = {
...module.exports,
...popperMixins,
}