mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REF] move event_bus into utils, readd 2 functions
This commit is contained in:
committed by
Aaron Bohy
parent
c1439814bf
commit
1658d15b87
+2
-1
@@ -31,7 +31,7 @@ export class App<T extends typeof Component = any> extends TemplateSet {
|
|||||||
this.props = props;
|
this.props = props;
|
||||||
}
|
}
|
||||||
|
|
||||||
configure(config: Config) {
|
configure(config: Config): App<T> {
|
||||||
if (config.dev) {
|
if (config.dev) {
|
||||||
this.dev = config.dev;
|
this.dev = config.dev;
|
||||||
console.info(DEV_MSG);
|
console.info(DEV_MSG);
|
||||||
@@ -46,6 +46,7 @@ export class App<T extends typeof Component = any> extends TemplateSet {
|
|||||||
if (config.translatableAttributes) {
|
if (config.translatableAttributes) {
|
||||||
this.translatableAttributes = config.translatableAttributes;
|
this.translatableAttributes = config.translatableAttributes;
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
mount(target: HTMLElement, options?: MountOptions): Promise<InstanceType<T>> {
|
mount(target: HTMLElement, options?: MountOptions): Promise<InstanceType<T>> {
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
import { BDom, multi, text, toggler } from "../blockdom";
|
import { BDom, multi, text, toggler } from "../blockdom";
|
||||||
import { validateProps } from "../component/props_validation";
|
import { validateProps } from "../component/props_validation";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file contains utility functions that will be injected in each template,
|
||||||
|
* to perform various useful tasks in the compiled code.
|
||||||
|
*/
|
||||||
|
|
||||||
function withDefault(value: any, defaultValue: any): any {
|
function withDefault(value: any, defaultValue: any): any {
|
||||||
return value === undefined || value === null || value === false ? defaultValue : value;
|
return value === undefined || value === null || value === false ? defaultValue : value;
|
||||||
}
|
}
|
||||||
@@ -19,7 +24,6 @@ function callSlot(
|
|||||||
if (defaultSlot) {
|
if (defaultSlot) {
|
||||||
let child1: BDom | undefined = undefined;
|
let child1: BDom | undefined = undefined;
|
||||||
let child2: BDom | undefined = undefined;
|
let child2: BDom | undefined = undefined;
|
||||||
// const result = new BMulti(2);
|
|
||||||
if (slotBDom) {
|
if (slotBDom) {
|
||||||
child1 = dynamic ? toggler(name, slotBDom) : slotBDom;
|
child1 = dynamic ? toggler(name, slotBDom) : slotBDom;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { mount } from "../blockdom";
|
|||||||
import type { ComponentNode } from "./component_node";
|
import type { ComponentNode } from "./component_node";
|
||||||
import { STATUS } from "./status";
|
import { STATUS } from "./status";
|
||||||
import { fibersInError } from "./error_handling";
|
import { fibersInError } from "./error_handling";
|
||||||
// import { mountBlock } from "./bdom/block";
|
|
||||||
|
|
||||||
export function makeChildFiber(node: ComponentNode, parent: Fiber): Fiber {
|
export function makeChildFiber(node: ComponentNode, parent: Fiber): Fiber {
|
||||||
let current = node.fiber;
|
let current = node.fiber;
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
export class EventBus extends EventTarget {
|
|
||||||
trigger(name: string, payload?: any) {
|
|
||||||
this.dispatchEvent(new CustomEvent(name, { detail: payload }));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-1
@@ -11,6 +11,7 @@ import {
|
|||||||
toggler,
|
toggler,
|
||||||
} from "./blockdom";
|
} from "./blockdom";
|
||||||
import { mainEventHandler } from "./component/handler";
|
import { mainEventHandler } from "./component/handler";
|
||||||
|
import { EventBus, whenReady, loadFile } from "./utils";
|
||||||
|
|
||||||
config.shouldNormalizeDom = false;
|
config.shouldNormalizeDom = false;
|
||||||
config.mainEventHandler = mainEventHandler;
|
config.mainEventHandler = mainEventHandler;
|
||||||
@@ -57,7 +58,7 @@ export { Memo } from "./misc/memo";
|
|||||||
export { css, xml } from "./tags";
|
export { css, xml } from "./tags";
|
||||||
export { useState } from "./reactivity";
|
export { useState } from "./reactivity";
|
||||||
export { useRef } from "./refs";
|
export { useRef } from "./refs";
|
||||||
export { EventBus } from "./event_bus";
|
export const utils = { EventBus, whenReady, loadFile };
|
||||||
|
|
||||||
export {
|
export {
|
||||||
onWillStart,
|
onWillStart,
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
export class EventBus extends EventTarget {
|
||||||
|
trigger(name: string, payload?: any) {
|
||||||
|
this.dispatchEvent(new CustomEvent(name, { detail: payload }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function whenReady(fn?: any): Promise<void> {
|
||||||
|
return new Promise(function (resolve) {
|
||||||
|
if (document.readyState !== "loading") {
|
||||||
|
resolve(true);
|
||||||
|
} else {
|
||||||
|
document.addEventListener("DOMContentLoaded", resolve, false);
|
||||||
|
}
|
||||||
|
}).then(fn || function () {});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function loadFile(url: string): Promise<string> {
|
||||||
|
const result = await fetch(url);
|
||||||
|
if (!result.ok) {
|
||||||
|
throw new Error("Error while fetching xml templates");
|
||||||
|
}
|
||||||
|
return await result.text();
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { EventBus } from "../src/event_bus";
|
import { EventBus } from "../src/utils";
|
||||||
|
|
||||||
describe("event bus behaviour", () => {
|
describe("event bus behaviour", () => {
|
||||||
test("can subscribe and be notified", () => {
|
test("can subscribe and be notified", () => {
|
||||||
Reference in New Issue
Block a user