forked from domvm/domvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevmode.js
48 lines (37 loc) · 1.82 KB
/
devmode.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
export const DEVMODE = {
enabled: true,
verbose: true,
AUTOKEYED_VIEW: function(vm, model) {
var msg = "A view has been auto-keyed by its model's identity. If this model is replaced between redraws,"
+ " this view will unmount, its internal state and DOM will be destroyed and recreated."
+ " Consider providing a fixed key to this view to ensure its persistence & DOM recycling. See https://github.com/leeoniya/domvm#dom-recycling.";
return [msg, vm, model];
},
UNKEYED_INPUT: function(vnode) {
return ["Unkeyed <input> detected. Consider adding a name, id, _key, or _ref attr to avoid accidental DOM recycling between different <input> types.", vnode];
},
UNMOUNTED_REDRAW: function(vm) {
return ["Invoking redraw() of an unmounted (sub)view may result in errors.", vm];
},
INLINE_HANDLER: function(vnode, oval, nval) {
return ["Anonymous event handlers get re-bound on each redraw, consider defining them outside of templates for better reuse.", vnode, oval, nval];
},
MISMATCHED_HANDLER: function(vnode, oval, nval) {
return ["Patching of different event handler styles is not fully supported for performance reasons. Ensure that handlers are defined using the same style.", vnode, oval, nval];
},
SVG_WRONG_FACTORY: function(vnode) {
return ["<svg> defined using domvm.defineElement. Use domvm.defineSvgElement for <svg> & child nodes.", vnode];
},
FOREIGN_ELEMENT: function(el) {
return ["domvm stumbled upon an element in its DOM that it didn't create, which may be problematic. You can inject external elements into the vtree using domvm.injectElement.", el];
},
}
export function devNotify(key, args) {
if (DEVMODE.enabled) {
var msgArgs = DEVMODE[key].apply(null, args);
if (msgArgs) {
msgArgs[0] = key + ": " + (DEVMODE.verbose ? msgArgs[0] : "");
console.warn.apply(null, msgArgs);
}
}
}