/
devmode.js
71 lines (54 loc) · 2.88 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { isFunc } from '../../utils';
export const DEVMODE = {
warnings: true,
verbose: true,
mutations: true,
DATA_REPLACED: function(vm, oldData, newData) {
if (isFunc(vm.view) && vm.view.length > 1) {
var msg = "A view's data was replaced. The data originally passed to the view closure during init is now stale. You may want to rely only on the data passed to render() or vm.data.";
return [msg, vm, oldData, newData];
}
},
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, nval) {
return ["Anonymous inline event handlers get re-created on every redraw, consider defining them outside of templates for better reuse.", vnode, 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];
},
REUSED_ATTRS: function(vnode) {
return ["Attrs objects may only be reused if they are truly static, as a perf optimization. Mutating & reusing them will have no effect on the DOM due to 0 diff.", vnode];
},
ADJACENT_TEXT: function(vnode, text1, text2) {
return ["Adjacent text nodes will be merged. Consider concatentating them yourself in the template for improved perf.", vnode, text1, text2];
},
ARRAY_FLATTENED: function(vnode, array) {
return ["Arrays within templates will be flattened. When they are leading or trailing, it's easy and more performant to just .concat() them in the template.", vnode, array];
},
ALREADY_HYDRATED: function(vm) {
return ["A child view failed to mount because it was already hydrated. Make sure not to invoke vm.redraw() or vm.update() on unmounted views.", vm];
},
ATTACH_IMPLICIT_TBODY: function(vnode, vchild) {
return ["<table><tr> was detected in the vtree, but the DOM will be <table><tbody><tr> after HTML's implicit parsing. You should create the <tbody> vnode explicitly to avoid SSR/attach() failures.", vnode, vchild];
}
}
export function devNotify(key, args) {
if (DEVMODE.warnings && isFunc(DEVMODE[key])) {
var msgArgs = DEVMODE[key].apply(null, args);
if (msgArgs) {
msgArgs[0] = key + ": " + (DEVMODE.verbose ? msgArgs[0] : "");
console.warn.apply(console, msgArgs);
}
}
}