mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-20 15:52:09 +02:00
Initial commit: Core packages
This commit is contained in:
commit
12c29a983b
9512 changed files with 8379910 additions and 0 deletions
|
|
@ -0,0 +1,36 @@
|
|||
(function () {
|
||||
const App = owl.App;
|
||||
|
||||
// templates' code is shared between multiple instances of Apps
|
||||
// This is useful primarly for the OWL2 to Legacy compatibility layer
|
||||
// It is also useful for tests.
|
||||
// The downside of this is that the compilation is done once with the compiling app's
|
||||
// translate function and attributes.
|
||||
const sharedTemplates = {};
|
||||
|
||||
owl.App = class extends App {
|
||||
constructor(_, config) {
|
||||
if (!config.test) {
|
||||
const missingKeys = ["dev", "translateFn", "translatableAttributes"].filter(
|
||||
(key) => !(key in config)
|
||||
);
|
||||
if (missingKeys.length) {
|
||||
throw new Error(
|
||||
`Attempted to create an App without some required key(s) (${missingKeys.join(
|
||||
", "
|
||||
)})`
|
||||
);
|
||||
}
|
||||
}
|
||||
super(...arguments);
|
||||
}
|
||||
_compileTemplate(name) {
|
||||
if (!(name in sharedTemplates)) {
|
||||
sharedTemplates[name] = super._compileTemplate(...arguments);
|
||||
}
|
||||
return sharedTemplates[name];
|
||||
}
|
||||
};
|
||||
owl.App.sharedTemplates = sharedTemplates;
|
||||
owl.App.validateTarget = () => {};
|
||||
})();
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
(function () {
|
||||
const { EventBus } = owl;
|
||||
|
||||
function wrapCallback(owner, callback) {
|
||||
return (ev) => {
|
||||
callback.call(owner, ev.detail);
|
||||
};
|
||||
}
|
||||
|
||||
owl.EventBus = class extends EventBus {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
this.targetsCallbacks = new Map();
|
||||
}
|
||||
on(type, target, callback) {
|
||||
if (!this.targetsCallbacks.has(target)) {
|
||||
this.targetsCallbacks.set(target, {});
|
||||
}
|
||||
callback = wrapCallback(target, callback);
|
||||
const listeners = this.targetsCallbacks.get(target);
|
||||
if (!listeners[type]) {
|
||||
listeners[type] = new Set();
|
||||
}
|
||||
listeners[type].add(callback);
|
||||
return this.addEventListener(type, callback);
|
||||
}
|
||||
off(type, target) {
|
||||
const listeners = this.targetsCallbacks.get(target);
|
||||
if (!listeners || !Object.hasOwnProperty.call(listeners, type)) {
|
||||
return;
|
||||
}
|
||||
const cbs = listeners[type];
|
||||
for (const callback of cbs) {
|
||||
this.removeEventListener(type, callback);
|
||||
}
|
||||
delete listeners[type];
|
||||
if (Object.keys(listeners).length === 0) {
|
||||
this.targetsCallbacks.delete(target);
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue