1 |
|
2 |
|
3 |
|
4 |
|
5 | export const lifecycleOptionalBehaviors = ['focus', 'if', 'else', 'repeat', 'show', 'hide', 'with'];
|
6 |
|
7 | function behaviorRequiresLifecycle(instruction) {
|
8 | let t = instruction.type;
|
9 | let name = t.elementName !== null ? t.elementName : t.attributeName;
|
10 | return lifecycleOptionalBehaviors.indexOf(name) === -1 && (t.handlesAttached || t.handlesBind || t.handlesCreated || t.handlesDetached || t.handlesUnbind)
|
11 | || t.viewFactory && viewsRequireLifecycle(t.viewFactory)
|
12 | || instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory);
|
13 | }
|
14 |
|
15 | function targetRequiresLifecycle(instruction) {
|
16 |
|
17 | let behaviors = instruction.behaviorInstructions;
|
18 | if (behaviors) {
|
19 | let i = behaviors.length;
|
20 | while (i--) {
|
21 | if (behaviorRequiresLifecycle(behaviors[i])) {
|
22 | return true;
|
23 | }
|
24 | }
|
25 | }
|
26 |
|
27 |
|
28 | return instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory);
|
29 | }
|
30 |
|
31 | export function viewsRequireLifecycle(viewFactory) {
|
32 |
|
33 | if ('_viewsRequireLifecycle' in viewFactory) {
|
34 | return viewFactory._viewsRequireLifecycle;
|
35 | }
|
36 |
|
37 |
|
38 | viewFactory._viewsRequireLifecycle = false;
|
39 |
|
40 |
|
41 | if (viewFactory.viewFactory) {
|
42 | viewFactory._viewsRequireLifecycle = viewsRequireLifecycle(viewFactory.viewFactory);
|
43 | return viewFactory._viewsRequireLifecycle;
|
44 | }
|
45 |
|
46 |
|
47 | if (viewFactory.template.querySelector('.au-animate')) {
|
48 | viewFactory._viewsRequireLifecycle = true;
|
49 | return true;
|
50 | }
|
51 |
|
52 |
|
53 | for (let id in viewFactory.instructions) {
|
54 | if (targetRequiresLifecycle(viewFactory.instructions[id])) {
|
55 | viewFactory._viewsRequireLifecycle = true;
|
56 | return true;
|
57 | }
|
58 | }
|
59 |
|
60 |
|
61 | viewFactory._viewsRequireLifecycle = false;
|
62 | return false;
|
63 | }
|