mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] devtools: Missing global owl
This commit adapts the behavior of the devtools global hook to get the toRaw and reactive functions from the __OWL_DEVTOOLS__ variable instead of the global owl when it is missing. Also adds the functions to the __OWL_DEVTOOLS__ variable for the former to work. This allows the devtools to work in environments where owl is loaded through ES modules. Also quickly fixes iframes detection update on page reload.
This commit is contained in:
committed by
Géry Debongnie
parent
77a413d750
commit
310730782c
@@ -7,6 +7,7 @@ import { Scheduler } from "./scheduler";
|
|||||||
import { validateProps } from "./template_helpers";
|
import { validateProps } from "./template_helpers";
|
||||||
import { TemplateSet, TemplateSetConfig } from "./template_set";
|
import { TemplateSet, TemplateSetConfig } from "./template_set";
|
||||||
import { validateTarget } from "./utils";
|
import { validateTarget } from "./utils";
|
||||||
|
import { toRaw, reactive } from "./reactivity";
|
||||||
|
|
||||||
// reimplement dev mode stuff see last change in 0f7a8289a6fb8387c3c1af41c6664b2a8448758f
|
// reimplement dev mode stuff see last change in 0f7a8289a6fb8387c3c1af41c6664b2a8448758f
|
||||||
|
|
||||||
@@ -39,6 +40,8 @@ declare global {
|
|||||||
apps: Set<App>;
|
apps: Set<App>;
|
||||||
Fiber: typeof Fiber;
|
Fiber: typeof Fiber;
|
||||||
RootFiber: typeof RootFiber;
|
RootFiber: typeof RootFiber;
|
||||||
|
toRaw: typeof toRaw;
|
||||||
|
reactive: typeof reactive;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,6 +50,8 @@ window.__OWL_DEVTOOLS__ ||= {
|
|||||||
apps: new Set<App>(),
|
apps: new Set<App>(),
|
||||||
Fiber: Fiber,
|
Fiber: Fiber,
|
||||||
RootFiber: RootFiber,
|
RootFiber: RootFiber,
|
||||||
|
toRaw: toRaw,
|
||||||
|
reactive: reactive,
|
||||||
};
|
};
|
||||||
|
|
||||||
export class App<
|
export class App<
|
||||||
|
|||||||
@@ -513,6 +513,7 @@ export const store = reactive({
|
|||||||
evalFunctionInWindow("toggleTracing", [false]);
|
evalFunctionInWindow("toggleTracing", [false]);
|
||||||
this.traceSubscriptions = false;
|
this.traceSubscriptions = false;
|
||||||
evalFunctionInWindow("toggleSubscriptionTracing", [false]);
|
evalFunctionInWindow("toggleSubscriptionTracing", [false]);
|
||||||
|
this.updateIFrameList();
|
||||||
},
|
},
|
||||||
|
|
||||||
// Triggers manually the rendering of the selected component
|
// Triggers manually the rendering of the selected component
|
||||||
|
|||||||
@@ -11,6 +11,10 @@
|
|||||||
this.Fiber = window.__OWL_DEVTOOLS__.Fiber;
|
this.Fiber = window.__OWL_DEVTOOLS__.Fiber;
|
||||||
// Same but for RootFiber
|
// Same but for RootFiber
|
||||||
this.RootFiber = window.__OWL_DEVTOOLS__.RootFiber;
|
this.RootFiber = window.__OWL_DEVTOOLS__.RootFiber;
|
||||||
|
// This is for retrocompatibility purposes since new versions of owl should always expose toRaw and reactive
|
||||||
|
// in __OWL_DEVTOOLS__
|
||||||
|
this.toRaw = window.__OWL_DEVTOOLS__.toRaw ?? window.owl?.toRaw;
|
||||||
|
this.reactive = window.__OWL_DEVTOOLS__.reactive ?? window.owl?.reactive;
|
||||||
// Set to keep track of the fibers that are in the flush queue
|
// Set to keep track of the fibers that are in the flush queue
|
||||||
this.queuedFibers = new WeakSet();
|
this.queuedFibers = new WeakSet();
|
||||||
// Set to keep track of the HTML elements we added to the page
|
// Set to keep track of the HTML elements we added to the page
|
||||||
@@ -400,7 +404,7 @@
|
|||||||
let targetToKeysToCallbacks;
|
let targetToKeysToCallbacks;
|
||||||
|
|
||||||
// Step 1: extract internal values from owl
|
// Step 1: extract internal values from owl
|
||||||
const obj = owl.reactive({}, () => {});
|
const obj = self.reactive({}, () => {});
|
||||||
let count = 0;
|
let count = 0;
|
||||||
WeakMap.prototype.get = function () {
|
WeakMap.prototype.get = function () {
|
||||||
count++;
|
count++;
|
||||||
@@ -728,7 +732,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (obj) {
|
if (obj) {
|
||||||
obj = owl.toRaw(obj);
|
obj = this.toRaw(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
@@ -836,7 +840,7 @@
|
|||||||
child.contentType = "undefined";
|
child.contentType = "undefined";
|
||||||
child.hasChildren = false;
|
child.hasChildren = false;
|
||||||
} else {
|
} else {
|
||||||
obj = owl.toRaw(obj);
|
obj = this.toRaw(obj);
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case obj instanceof Map:
|
case obj instanceof Map:
|
||||||
child.contentType = "map";
|
child.contentType = "map";
|
||||||
@@ -1388,7 +1392,7 @@
|
|||||||
}
|
}
|
||||||
getter.hasChildren = false;
|
getter.hasChildren = false;
|
||||||
} else {
|
} else {
|
||||||
obj = owl.toRaw(obj);
|
obj = this.toRaw(obj);
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case obj instanceof Map:
|
case obj instanceof Map:
|
||||||
getter.contentType = "map";
|
getter.contentType = "map";
|
||||||
@@ -1483,7 +1487,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (objectType === "subscription") {
|
if (objectType === "subscription") {
|
||||||
owl.reactive(obj)[key] = value;
|
this.reactive(obj)[key] = value;
|
||||||
} else {
|
} else {
|
||||||
obj[key] = value;
|
obj[key] = value;
|
||||||
if (objectType === "props" || objectType === "instance") {
|
if (objectType === "props" || objectType === "instance") {
|
||||||
|
|||||||
Reference in New Issue
Block a user