@odoo/owl 1.4.8 → 2.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +60 -66
  2. package/dist/owl.cjs.js +4629 -5046
  3. package/dist/owl.cjs.min.js +1 -15
  4. package/dist/owl.es.js +4601 -5036
  5. package/dist/owl.es.min.js +1 -15
  6. package/dist/owl.iife.js +4629 -5046
  7. package/dist/owl.iife.min.js +1 -15
  8. package/dist/types/app/app.d.ts +29 -0
  9. package/dist/types/app/template_helpers.d.ts +49 -0
  10. package/dist/types/app/template_set.d.ts +34 -0
  11. package/dist/types/blockdom/attributes.d.ts +8 -0
  12. package/dist/types/blockdom/block_compiler.d.ts +21 -0
  13. package/dist/types/blockdom/config.d.ts +8 -0
  14. package/dist/types/blockdom/events.d.ts +7 -0
  15. package/dist/types/blockdom/html.d.ts +16 -0
  16. package/dist/types/blockdom/index.d.ts +24 -0
  17. package/dist/types/blockdom/list.d.ts +17 -0
  18. package/dist/types/blockdom/multi.d.ts +16 -0
  19. package/dist/types/blockdom/text.d.ts +25 -0
  20. package/dist/types/blockdom/toggler.d.ts +16 -0
  21. package/dist/types/compiler/code_generator.d.ts +144 -0
  22. package/dist/types/compiler/index.d.ts +9 -0
  23. package/dist/types/{qweb/expression_parser.d.ts → compiler/inline_expressions.d.ts} +5 -6
  24. package/dist/types/compiler/parser.d.ts +157 -0
  25. package/dist/types/component/component.d.ts +15 -294
  26. package/dist/types/component/component_node.d.ts +54 -0
  27. package/dist/types/component/error_handling.d.ts +13 -0
  28. package/dist/types/component/fibers.d.ts +32 -0
  29. package/dist/types/component/handler.d.ts +1 -0
  30. package/dist/types/component/lifecycle_hooks.d.ts +12 -0
  31. package/dist/types/component/props_validation.d.ts +14 -1
  32. package/dist/types/component/scheduler.d.ts +5 -21
  33. package/dist/types/component/status.d.ts +9 -0
  34. package/dist/types/hooks.d.ts +26 -35
  35. package/dist/types/index.d.ts +27 -47
  36. package/dist/types/memo.d.ts +6 -0
  37. package/dist/types/portal.d.ts +11 -0
  38. package/dist/types/reactivity.d.ts +64 -0
  39. package/dist/types/utils.d.ts +14 -21
  40. package/package.json +14 -9
  41. package/dist/types/browser.d.ts +0 -12
  42. package/dist/types/component/directive.d.ts +0 -1
  43. package/dist/types/component/fiber.d.ts +0 -75
  44. package/dist/types/component/styles.d.ts +0 -12
  45. package/dist/types/config.d.ts +0 -12
  46. package/dist/types/context.d.ts +0 -36
  47. package/dist/types/core/event_bus.d.ts +0 -42
  48. package/dist/types/core/observer.d.ts +0 -30
  49. package/dist/types/core/owl_event.d.ts +0 -10
  50. package/dist/types/misc/async_root.d.ts +0 -13
  51. package/dist/types/misc/portal.d.ts +0 -70
  52. package/dist/types/qweb/base_directives.d.ts +0 -1
  53. package/dist/types/qweb/compilation_context.d.ts +0 -69
  54. package/dist/types/qweb/extensions.d.ts +0 -28
  55. package/dist/types/qweb/index.d.ts +0 -3
  56. package/dist/types/qweb/qweb.d.ts +0 -141
  57. package/dist/types/router/link.d.ts +0 -11
  58. package/dist/types/router/route_component.d.ts +0 -6
  59. package/dist/types/router/router.d.ts +0 -57
  60. package/dist/types/store.d.ts +0 -63
  61. package/dist/types/tags.d.ts +0 -29
  62. package/dist/types/vdom/html_to_vdom.d.ts +0 -2
  63. package/dist/types/vdom/index.d.ts +0 -2
  64. package/dist/types/vdom/modules.d.ts +0 -5
  65. package/dist/types/vdom/vdom.d.ts +0 -101
@@ -0,0 +1,25 @@
1
+ import type { VNode } from "./index";
2
+ declare abstract class VSimpleNode {
3
+ text: string | String;
4
+ parentEl?: HTMLElement | undefined;
5
+ el?: any;
6
+ constructor(text: string | String);
7
+ mountNode(node: Node, parent: HTMLElement, afterNode: Node | null): void;
8
+ moveBefore(other: VText | null, afterNode: Node | null): void;
9
+ beforeRemove(): void;
10
+ remove(): void;
11
+ firstNode(): Node;
12
+ toString(): string | String;
13
+ }
14
+ declare class VText extends VSimpleNode {
15
+ mount(parent: HTMLElement, afterNode: Node | null): void;
16
+ patch(other: VText): void;
17
+ }
18
+ declare class VComment extends VSimpleNode {
19
+ mount(parent: HTMLElement, afterNode: Node | null): void;
20
+ patch(): void;
21
+ }
22
+ export declare function text(str: string | String): VNode<VText>;
23
+ export declare function comment(str: string): VNode<VComment>;
24
+ export declare function toText(value: any): string;
25
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { VNode } from "./index";
2
+ declare class VToggler {
3
+ key: string;
4
+ child: VNode;
5
+ parentEl?: HTMLElement | undefined;
6
+ constructor(key: string, child: VNode);
7
+ mount(parent: HTMLElement, afterNode: Node | null): void;
8
+ moveBefore(other: VToggler | null, afterNode: Node | null): void;
9
+ patch(other: VToggler, withBeforeRemove: boolean): void;
10
+ beforeRemove(): void;
11
+ remove(): void;
12
+ firstNode(): Node | undefined;
13
+ toString(): string;
14
+ }
15
+ export declare function toggler(key: string, child: VNode): VNode<VToggler>;
16
+ export {};
@@ -0,0 +1,144 @@
1
+ import { AST, ASTComment, ASTComponent, ASTDebug, ASTDomNode, ASTLog, ASTMulti, ASTSlot, ASTTCall, ASTTCallBlock, ASTTEsc, ASTText, ASTTForEach, ASTTif, ASTTKey, ASTTOut, ASTTSet, ASTTranslation, ASTTPortal } from "./parser";
2
+ declare type BlockType = "block" | "text" | "multi" | "list" | "html" | "comment";
3
+ export interface Config {
4
+ translateFn?: (s: string) => string;
5
+ translatableAttributes?: string[];
6
+ dev?: boolean;
7
+ }
8
+ export interface CodeGenOptions extends Config {
9
+ hasSafeContext?: boolean;
10
+ name?: string;
11
+ }
12
+ declare class BlockDescription {
13
+ static nextBlockId: number;
14
+ static nextDataIds: {
15
+ [key: string]: number;
16
+ };
17
+ static generateId(prefix: string): string;
18
+ varName: string;
19
+ blockName: string;
20
+ dynamicTagName: string | null;
21
+ isRoot: boolean;
22
+ hasDynamicChildren: boolean;
23
+ children: BlockDescription[];
24
+ data: string[];
25
+ dom?: Node;
26
+ currentDom?: Element;
27
+ childNumber: number;
28
+ target: CodeTarget;
29
+ type: BlockType;
30
+ parentVar: string;
31
+ id: number;
32
+ constructor(target: CodeTarget, type: BlockType);
33
+ insertData(str: string, prefix?: string): number;
34
+ insert(dom: Node): void;
35
+ generateExpr(expr: string): string;
36
+ asXmlString(): string;
37
+ }
38
+ interface Context {
39
+ block: BlockDescription | null;
40
+ index: number | string;
41
+ forceNewBlock: boolean;
42
+ preventRoot?: boolean;
43
+ isLast?: boolean;
44
+ translate: boolean;
45
+ tKeyExpr: string | null;
46
+ nameSpace?: string;
47
+ tModelSelectedExpr?: string;
48
+ }
49
+ declare class CodeTarget {
50
+ name: string;
51
+ indentLevel: number;
52
+ loopLevel: number;
53
+ code: string[];
54
+ hasRoot: boolean;
55
+ hasCache: boolean;
56
+ hasRef: boolean;
57
+ refInfo: {
58
+ [name: string]: [string, string];
59
+ };
60
+ shouldProtectScope: boolean;
61
+ constructor(name: string);
62
+ addLine(line: string, idx?: number): void;
63
+ generateCode(): string;
64
+ }
65
+ export declare class CodeGenerator {
66
+ blocks: BlockDescription[];
67
+ ids: {
68
+ [key: string]: number;
69
+ };
70
+ nextBlockId: number;
71
+ hasSafeContext: boolean;
72
+ isDebug: boolean;
73
+ targets: CodeTarget[];
74
+ target: CodeTarget;
75
+ templateName?: string;
76
+ dev: boolean;
77
+ translateFn: (s: string) => string;
78
+ translatableAttributes: string[];
79
+ ast: AST;
80
+ staticCalls: {
81
+ id: string;
82
+ template: string;
83
+ }[];
84
+ helpers: Set<string>;
85
+ constructor(ast: AST, options: CodeGenOptions);
86
+ generateCode(): string;
87
+ compileInNewTarget(prefix: string, ast: AST, ctx: Context): string;
88
+ addLine(line: string): void;
89
+ generateId(prefix?: string): string;
90
+ insertAnchor(block: BlockDescription): void;
91
+ createBlock(parentBlock: BlockDescription | null, type: BlockType, ctx: Context): BlockDescription;
92
+ insertBlock(expression: string, block: BlockDescription, ctx: Context): void;
93
+ /**
94
+ * Captures variables that are used inside of an expression. This is useful
95
+ * because in compiled code, almost all variables are accessed through the ctx
96
+ * object. In the case of functions, that lookup in the context can be delayed
97
+ * which can cause issues if the value has changed since the function was
98
+ * defined.
99
+ *
100
+ * @param expr the expression to capture
101
+ * @param forceCapture whether the expression should capture its scope even if
102
+ * it doesn't contain a function. Useful when the expression will be used as
103
+ * a function body.
104
+ * @returns a new expression that uses the captured values
105
+ */
106
+ captureExpression(expr: string, forceCapture?: boolean): string;
107
+ compileAST(ast: AST, ctx: Context): void;
108
+ compileDebug(ast: ASTDebug, ctx: Context): void;
109
+ compileLog(ast: ASTLog, ctx: Context): void;
110
+ compileComment(ast: ASTComment, ctx: Context): void;
111
+ compileText(ast: ASTText, ctx: Context): void;
112
+ generateHandlerCode(rawEvent: string, handler: string): string;
113
+ compileTDomNode(ast: ASTDomNode, ctx: Context): void;
114
+ compileTEsc(ast: ASTTEsc, ctx: Context): void;
115
+ compileTOut(ast: ASTTOut, ctx: Context): void;
116
+ compileTIf(ast: ASTTif, ctx: Context, nextNode?: ASTDomNode): void;
117
+ compileTForeach(ast: ASTTForEach, ctx: Context): void;
118
+ compileTKey(ast: ASTTKey, ctx: Context): void;
119
+ compileMulti(ast: ASTMulti, ctx: Context): void;
120
+ compileTCall(ast: ASTTCall, ctx: Context): void;
121
+ compileTCallBlock(ast: ASTTCallBlock, ctx: Context): void;
122
+ compileTSet(ast: ASTTSet, ctx: Context): void;
123
+ generateComponentKey(): string;
124
+ /**
125
+ * Formats a prop name and value into a string suitable to be inserted in the
126
+ * generated code. For example:
127
+ *
128
+ * Name Value Result
129
+ * ---------------------------------------------------------
130
+ * "number" "state" "number: ctx['state']"
131
+ * "something" "" "something: undefined"
132
+ * "some-prop" "state" "'some-prop': ctx['state']"
133
+ * "onClick.bind" "onClick" "onClick: bind(ctx, ctx['onClick'])"
134
+ */
135
+ formatProp(name: string, value: string): string;
136
+ formatPropObject(obj: {
137
+ [prop: string]: any;
138
+ }): string;
139
+ compileComponent(ast: ASTComponent, ctx: Context): void;
140
+ compileTSlot(ast: ASTSlot, ctx: Context): void;
141
+ compileTTranslation(ast: ASTTranslation, ctx: Context): void;
142
+ compileTPortal(ast: ASTTPortal, ctx: Context): void;
143
+ }
144
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { BDom } from "../blockdom";
2
+ import { Config } from "./code_generator";
3
+ export declare type Template = (context: any, vnode: any, key?: string) => BDom;
4
+ export declare type TemplateFunction = (blocks: any, utils: any) => Template;
5
+ interface CompileOptions extends Config {
6
+ name?: string;
7
+ }
8
+ export declare function compile(template: string | Element, options?: CompileOptions): TemplateFunction;
9
+ export {};
@@ -34,6 +34,7 @@ interface Token {
34
34
  size?: number;
35
35
  varName?: string;
36
36
  replace?: Function;
37
+ isLocal?: boolean;
37
38
  }
38
39
  /**
39
40
  * Convert a javascript expression (as a string) into a list of tokens. For
@@ -72,10 +73,8 @@ export declare function tokenize(expr: string): Token[];
72
73
  * the arrow operator, then we add the current (or some previous tokens) token to
73
74
  * the list of variables so it does not get replaced by a lookup in the context
74
75
  */
75
- export declare function compileExprToArray(expr: string, scope: {
76
- [key: string]: QWebVar;
77
- }): Token[];
78
- export declare function compileExpr(expr: string, scope: {
79
- [key: string]: QWebVar;
80
- }): string;
76
+ export declare function compileExprToArray(expr: string): Token[];
77
+ export declare function compileExpr(expr: string): string;
78
+ export declare const INTERP_REGEXP: RegExp;
79
+ export declare function interpolate(s: string): string;
81
80
  export {};
@@ -0,0 +1,157 @@
1
+ export declare const enum ASTType {
2
+ Text = 0,
3
+ Comment = 1,
4
+ DomNode = 2,
5
+ Multi = 3,
6
+ TEsc = 4,
7
+ TIf = 5,
8
+ TSet = 6,
9
+ TCall = 7,
10
+ TOut = 8,
11
+ TForEach = 9,
12
+ TKey = 10,
13
+ TComponent = 11,
14
+ TDebug = 12,
15
+ TLog = 13,
16
+ TSlot = 14,
17
+ TCallBlock = 15,
18
+ TTranslation = 16,
19
+ TPortal = 17
20
+ }
21
+ export interface ASTText {
22
+ type: ASTType.Text;
23
+ value: string;
24
+ }
25
+ export interface ASTComment {
26
+ type: ASTType.Comment;
27
+ value: string;
28
+ }
29
+ interface TModelInfo {
30
+ hasDynamicChildren?: boolean;
31
+ baseExpr: string;
32
+ expr: string;
33
+ targetAttr: string;
34
+ specialInitTargetAttr: string | null;
35
+ eventType: "change" | "click" | "input";
36
+ shouldTrim: boolean;
37
+ shouldNumberize: boolean;
38
+ }
39
+ export interface ASTDomNode {
40
+ type: ASTType.DomNode;
41
+ tag: string;
42
+ dynamicTag: string | null;
43
+ attrs: {
44
+ [key: string]: string;
45
+ };
46
+ content: AST[];
47
+ ref: string | null;
48
+ on: {
49
+ [key: string]: string;
50
+ };
51
+ model?: TModelInfo | null;
52
+ ns: string | null;
53
+ }
54
+ export interface ASTMulti {
55
+ type: ASTType.Multi;
56
+ content: AST[];
57
+ }
58
+ export interface ASTTEsc {
59
+ type: ASTType.TEsc;
60
+ expr: string;
61
+ defaultValue: string;
62
+ }
63
+ export interface ASTTOut {
64
+ type: ASTType.TOut;
65
+ expr: string;
66
+ body: AST[] | null;
67
+ }
68
+ export interface ASTTif {
69
+ type: ASTType.TIf;
70
+ condition: string;
71
+ content: AST;
72
+ tElif: {
73
+ condition: string;
74
+ content: AST;
75
+ }[] | null;
76
+ tElse: AST | null;
77
+ }
78
+ export interface ASTTSet {
79
+ type: ASTType.TSet;
80
+ name: string;
81
+ value: string | null;
82
+ defaultValue: string | null;
83
+ body: AST[] | null;
84
+ }
85
+ export interface ASTTForEach {
86
+ type: ASTType.TForEach;
87
+ collection: string;
88
+ elem: string;
89
+ key: string | null;
90
+ body: AST;
91
+ memo: string;
92
+ hasNoFirst: boolean;
93
+ hasNoLast: boolean;
94
+ hasNoIndex: boolean;
95
+ hasNoValue: boolean;
96
+ }
97
+ export interface ASTTKey {
98
+ type: ASTType.TKey;
99
+ expr: string;
100
+ content: AST;
101
+ }
102
+ export interface ASTTCall {
103
+ type: ASTType.TCall;
104
+ name: string;
105
+ body: AST[] | null;
106
+ }
107
+ export interface ASTComponent {
108
+ type: ASTType.TComponent;
109
+ name: string;
110
+ isDynamic: boolean;
111
+ dynamicProps: string | null;
112
+ props: {
113
+ [name: string]: string;
114
+ };
115
+ slots: {
116
+ [name: string]: {
117
+ content: AST;
118
+ attrs?: {
119
+ [key: string]: string;
120
+ };
121
+ scope?: string;
122
+ };
123
+ };
124
+ }
125
+ export interface ASTSlot {
126
+ type: ASTType.TSlot;
127
+ name: string;
128
+ attrs: {
129
+ [key: string]: string;
130
+ };
131
+ defaultContent: AST | null;
132
+ }
133
+ export interface ASTTCallBlock {
134
+ type: ASTType.TCallBlock;
135
+ name: string;
136
+ }
137
+ export interface ASTDebug {
138
+ type: ASTType.TDebug;
139
+ content: AST | null;
140
+ }
141
+ export interface ASTLog {
142
+ type: ASTType.TLog;
143
+ expr: string;
144
+ content: AST | null;
145
+ }
146
+ export interface ASTTranslation {
147
+ type: ASTType.TTranslation;
148
+ content: AST | null;
149
+ }
150
+ export interface ASTTPortal {
151
+ type: ASTType.TPortal;
152
+ target: string;
153
+ content: AST;
154
+ }
155
+ export declare type AST = ASTText | ASTComment | ASTDomNode | ASTMulti | ASTTEsc | ASTTif | ASTTSet | ASTTCall | ASTTOut | ASTTForEach | ASTTKey | ASTComponent | ASTSlot | ASTTCallBlock | ASTLog | ASTDebug | ASTTranslation | ASTTPortal;
156
+ export declare function parse(xml: string | Element): AST;
157
+ export {};
@@ -1,301 +1,22 @@
1
- import { Observer } from "../core/observer";
2
- import { CompiledTemplate, QWeb } from "../qweb/index";
3
- import { VNode } from "../vdom/index";
4
- import "./directive";
5
- import { Fiber } from "./fiber";
6
- import "./props_validation";
7
- import { Scheduler } from "./scheduler";
8
- import { Browser } from "../browser";
9
- /**
10
- * Owl Component System
11
- *
12
- * This file introduces a declarative and composable component system. It
13
- * contains:
14
- *
15
- * - the Env interface (generic type for the environment)
16
- * - the Internal interface (the owl specific metadata attached to a component)
17
- * - the Component class
18
- */
19
- /**
20
- * An Env (environment) is an object that will be (mostly) shared between all
21
- * components of an Owl application. It is the location which should contain
22
- * the qweb instance necessary to render all components.
23
- *
24
- * Note that it is totally fine to extend the environment with application
25
- * specific keys/objects/whatever. For example, a key `isMobile` (to declare
26
- * if we are in "mobile" mode), or a shared bus could be useful.
27
- */
28
- export interface Env {
29
- qweb: QWeb;
30
- browser: Browser;
31
- }
32
- export declare type MountPosition = "first-child" | "last-child" | "self";
33
- interface MountOptions {
34
- position?: MountPosition;
35
- }
36
- export declare const enum STATUS {
37
- CREATED = 0,
38
- WILLSTARTED = 1,
39
- RENDERED = 2,
40
- MOUNTED = 3,
41
- UNMOUNTED = 4,
42
- DESTROYED = 5
43
- }
44
- /**
45
- * This is mostly an internal detail of implementation. The Meta interface is
46
- * useful to typecheck and describe the internal keys used by Owl to manage the
47
- * component tree.
48
- */
49
- interface Internal<T extends Env> {
50
- readonly id: number;
51
- depth: number;
52
- vnode: VNode | null;
53
- pvnode: VNode | null;
54
- status: STATUS;
55
- parent: Component<any, T> | null;
56
- children: {
57
- [key: number]: Component<any, T>;
58
- };
59
- cmap: {
60
- [key: number]: number;
61
- };
62
- currentFiber: Fiber | null;
63
- parentLastFiberId: number;
64
- scope: any;
65
- boundHandlers: {
66
- [key: number]: any;
67
- };
68
- observer: Observer | null;
69
- renderFn: CompiledTemplate;
70
- mountedCB: Function | null;
71
- willUnmountCB: Function | null;
72
- willPatchCB: Function | null;
73
- patchedCB: Function | null;
74
- willStartCB: Function | null;
75
- willUpdatePropsCB: Function | null;
76
- classObj: {
77
- [key: string]: boolean;
78
- } | null;
79
- refs: {
80
- [key: string]: Component<any, T> | HTMLElement | undefined;
81
- } | null;
1
+ import type { ComponentNode } from "./component_node";
2
+ declare type Props = {
3
+ [key: string]: any;
4
+ };
5
+ interface StaticComponentProperties {
6
+ template: string;
7
+ defaultProps?: any;
8
+ props?: any;
82
9
  }
83
- export declare const portalSymbol: unique symbol;
84
- export declare class Component<Props extends {} = any, T extends Env = Env> {
85
- readonly __owl__: Internal<T>;
86
- static template?: string | null;
87
- static _template?: string | null;
88
- static current: Component | null;
89
- static components: {};
10
+ export declare type ComponentConstructor<P extends Props = any, E = any> = (new (props: P, env: E, node: ComponentNode) => Component<P, E>) & StaticComponentProperties;
11
+ export declare class Component<Props = any, Env = any> {
12
+ static template: string;
90
13
  static props?: any;
91
14
  static defaultProps?: any;
92
- static env: any;
93
- static scheduler: Scheduler;
94
- /**
95
- * The `el` is the root element of the component. Note that it could be null:
96
- * this is the case if the component is not mounted yet, or is destroyed.
97
- */
98
- get el(): HTMLElement | null;
99
- env: T;
100
15
  props: Props;
101
- /**
102
- * Creates an instance of Component.
103
- *
104
- * Note that most of the time, only the root component needs to be created by
105
- * hand. Other components should be created automatically by the framework (with
106
- * the t-component directive in a template)
107
- */
108
- constructor(parent?: Component<any, T> | null, props?: Props);
109
- /**
110
- * setup is run just after the component is constructed. This is the standard
111
- * location where the component can setup its hooks. It has some advantages
112
- * over the constructor:
113
- * - it can be patched (useful in odoo ecosystem)
114
- * - it does not need to propagate the arguments to the super call
115
- *
116
- * Note: this method should not be called manually.
117
- */
16
+ env: Env;
17
+ __owl__: ComponentNode;
18
+ constructor(props: Props, env: Env, node: ComponentNode);
118
19
  setup(): void;
119
- /**
120
- * willStart is an asynchronous hook that can be implemented to perform some
121
- * action before the initial rendering of a component.
122
- *
123
- * It will be called exactly once before the initial rendering. It is useful
124
- * in some cases, for example, to load external assets (such as a JS library)
125
- * before the component is rendered.
126
- *
127
- * Note that a slow willStart method will slow down the rendering of the user
128
- * interface. Therefore, some effort should be made to make this method as
129
- * fast as possible.
130
- *
131
- * Note: this method should not be called manually.
132
- */
133
- willStart(): Promise<void>;
134
- /**
135
- * mounted is a hook that is called each time a component is attached to the
136
- * DOM. This is a good place to add some listeners, or to interact with the
137
- * DOM, if the component needs to perform some measure for example.
138
- *
139
- * Note: this method should not be called manually.
140
- *
141
- * @see willUnmount
142
- */
143
- mounted(): void;
144
- /**
145
- * The willUpdateProps is an asynchronous hook, called just before new props
146
- * are set. This is useful if the component needs some asynchronous task
147
- * performed, depending on the props (for example, assuming that the props are
148
- * some record Id, fetching the record data).
149
- *
150
- * This hook is not called during the first render (but willStart is called
151
- * and performs a similar job).
152
- */
153
- willUpdateProps(nextProps: Props): Promise<void>;
154
- /**
155
- * The willPatch hook is called just before the DOM patching process starts.
156
- * It is not called on the initial render. This is useful to get some
157
- * information which are in the DOM. For example, the current position of the
158
- * scrollbar
159
- */
160
- willPatch(): any;
161
- /**
162
- * This hook is called whenever a component did actually update its props,
163
- * state or env.
164
- *
165
- * This method is not called on the initial render. It is useful to interact
166
- * with the DOM (for example, through an external library) whenever the
167
- * component was updated.
168
- *
169
- * Updating the component state in this hook is possible, but not encouraged.
170
- * One need to be careful, because updates here will cause rerender, which in
171
- * turn will cause other calls to updated. So, we need to be particularly
172
- * careful at avoiding endless cycles.
173
- */
174
- patched(): void;
175
- /**
176
- * willUnmount is a hook that is called each time just before a component is
177
- * unmounted from the DOM. This is a good place to remove some listeners, for
178
- * example.
179
- *
180
- * Note: this method should not be called manually.
181
- *
182
- * @see mounted
183
- */
184
- willUnmount(): void;
185
- /**
186
- * catchError is a method called whenever some error happens in the rendering or
187
- * lifecycle hooks of a child.
188
- *
189
- * It needs to be implemented by a component that is designed to handle the
190
- * error properly.
191
- */
192
- catchError?(error?: Error): void;
193
- /**
194
- * Mount the component to a target element.
195
- *
196
- * This should only be done if the component was created manually. Components
197
- * created declaratively in templates are managed by the Owl system.
198
- *
199
- * Note that a component can be mounted an unmounted several times
200
- */
201
- mount(target: HTMLElement | DocumentFragment, options?: MountOptions): Promise<void>;
202
- /**
203
- * The unmount method is the opposite of the mount method. It is useful
204
- * to call willUnmount calls and remove the component from the DOM.
205
- */
206
- unmount(): void;
207
- /**
208
- * The render method is the main entry point to render a component (once it
209
- * is ready. This method is not initially called when the component is
210
- * rendered the first time).
211
- *
212
- * This method will cause all its sub components to potentially rerender
213
- * themselves. Note that `render` is not called if a component is updated via
214
- * its props.
215
- */
216
- render(force?: boolean): Promise<void>;
217
- /**
218
- * Destroy the component. This operation is quite complex:
219
- * - it recursively destroy all children
220
- * - call the willUnmount hooks if necessary
221
- * - remove the dom node from the dom
222
- *
223
- * This should only be called manually if you created the component. Most
224
- * components will be automatically destroyed.
225
- */
226
- destroy(): void;
227
- /**
228
- * This method is called by the component system whenever its props are
229
- * updated. If it returns true, then the component will be rendered.
230
- * Otherwise, it will skip the rendering (also, its props will not be updated)
231
- */
232
- shouldUpdate(nextProps: Props): boolean;
233
- /**
234
- * Emit a custom event of type 'eventType' with the given 'payload' on the
235
- * component's el, if it exists. However, note that the event will only bubble
236
- * up to the parent DOM nodes. Thus, it must be called between mounted() and
237
- * willUnmount().
238
- */
239
- trigger<T = any>(eventType: string, payload?: T): void;
240
- /**
241
- * Private helper to perform a full destroy, from the point of view of an Owl
242
- * component. It does not remove the el (this is done only once on the top
243
- * level destroyed component, for performance reasons).
244
- *
245
- * The job of this method is mostly to call willUnmount hooks, and to perform
246
- * all necessary internal cleanup.
247
- *
248
- * Note that it does not call the __callWillUnmount method to avoid visiting
249
- * all children many times.
250
- */
251
- __destroy(parent: Component | null): void;
252
- __callMounted(): void;
253
- __callWillUnmount(): void;
254
- /**
255
- * Private trigger method, allows to choose the component which triggered
256
- * the event in the first place
257
- */
258
- __trigger<T>(component: Component, eventType: string, payload?: T): void;
259
- /**
260
- * The __updateProps method is called by the t-component directive whenever
261
- * it updates a component (so, when the parent template is rerendered).
262
- */
263
- __updateProps(nextProps: Props, parentFiber: Fiber, scope: any): Promise<void>;
264
- /**
265
- * Main patching method. We call the virtual dom patch method here to convert
266
- * a virtual dom vnode into some actual dom.
267
- */
268
- __patch(target: HTMLElement | VNode | DocumentFragment, vnode: VNode): void;
269
- /**
270
- * The __prepare method is only called by the t-component directive, when a
271
- * subcomponent is created. It gets its scope, if any, from the
272
- * parent template.
273
- */
274
- __prepare(parentFiber: Fiber, scope: any, cb: CallableFunction): Fiber;
275
- /**
276
- * Apply the stylesheets defined by the component. Note that we need to make
277
- * sure all inherited stylesheets are applied as well. We then delete the
278
- * `style` key from the constructor to make sure we do not apply it again.
279
- */
280
- private __applyStyles;
281
- __getTemplate(qweb: QWeb): string;
282
- __prepareAndRender(fiber: Fiber, cb: CallableFunction): Promise<void>;
283
- __render(fiber: Fiber): void;
284
- /**
285
- * Apply default props (only top level).
286
- *
287
- * Note that this method does modify in place the props
288
- */
289
- __applyDefaultProps(props: Object, defaultProps: Object): void;
290
- }
291
- interface MountParameters {
292
- env?: Env;
293
- target: HTMLElement | DocumentFragment;
294
- props?: any;
295
- position?: MountOptions["position"];
296
- }
297
- interface Type<T> extends Function {
298
- new (...args: any[]): T;
20
+ render(): void;
299
21
  }
300
- export declare function mount<T extends Type<Component>>(C: T, params: MountParameters): Promise<InstanceType<T>>;
301
22
  export {};