[REF] mail,*: adapt code to owl 2

*im_livechat,sms,snailmail

Owl 2 changelog: https://github.com/odoo/owl/blob/a9f29c4caad4f32d06be1ec4780572825781cd9b/CHANGELOG.md

Part-of: odoo/odoo#80156
Co-authored-by: Aaron Bohy <aab@odoo.com>
Co-authored-by: Bruno Boi <boi@odoo.com>
Co-authored-by: Géry Debongnie <ged@odoo.com>
Co-authored-by: Samuel Degueldre <sad@odoo.com>
Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Co-authored-by: Simon Genin (ges) <ges@odoo.com>
Co-authored-by: Francois (fge) <fge@odoo.com>
Co-authored-by: Michael Mattiello (mcm) <mcm@odoo.com>
Co-authored-by: Julien Mougenot <jum@odoo.com>
Co-authored-by: luvi <luvi@odoo.com>
Co-authored-by: Lucas Perais (lpe) <lpe@odoo.com>
Co-authored-by: Jorge Pinna Puissant <jpp@odoo.com>
This commit is contained in:
Samuel Degueldre
2022-02-10 07:46:13 +00:00
co-authored by Aaron Bohy Bruno Boi Géry Debongnie Mathieu Duckerts-Antoine Simon Genin Francois Michael Mattiello Julien Mougenot luvi Lucas Perais Jorge Pinna Puissant
parent 0c7910529d
commit edd79ff560
76 changed files with 445 additions and 362 deletions
@@ -2,7 +2,7 @@
import { clear } from '@mail/model/model_field_command';
const { onWillUpdateProps, useComponent } = owl;
const { onWillDestroy, onWillUpdateProps, useComponent } = owl;
/**
* This hook provides support for saving the reference of the component directly
@@ -30,12 +30,10 @@ export function useComponentToModel({ fieldName, modelName }) {
nextRecord.update({ [fieldName]: component });
}
});
const __destroy = component.__destroy;
component.__destroy = parent => {
onWillDestroy(() => {
const record = modelManager.models[modelName].get(component.props.localId);
if (record) {
record.update({ [fieldName]: clear() });
}
__destroy.call(component, parent);
};
});
}
@@ -2,7 +2,7 @@
import { Listener } from '@mail/model/model_listener';
const { useComponent } = owl;
const { onRendered, onWillDestroy, onWillRender, useComponent } = owl;
/**
* This hook provides support for automatically re-rendering when used records
@@ -24,23 +24,21 @@ export function useModels() {
name: `useModels() of ${component}`,
onChange: () => component.render(),
});
const __render = component.__render;
component.__render = fiber => {
onWillRender(() => {
if (modelManager) {
modelManager.startListening(listener);
}
__render.call(component, fiber);
});
onRendered(() => {
if (modelManager) {
modelManager.stopListening(listener);
}
};
const __destroy = component.__destroy;
component.__destroy = parent => {
});
onWillDestroy(() => {
if (modelManager) {
modelManager.removeListener(listener);
}
__destroy.call(component, parent);
};
});
modelManager.messagingCreatedPromise.then(() => {
component.render();
});
@@ -2,7 +2,7 @@
import { clear } from '@mail/model/model_field_command';
const { onWillUpdateProps, useComponent, useRef } = owl;
const { onWillDestroy, onWillUpdateProps, useComponent, useRef } = owl;
/**
* This hook provides support for saving the result of useRef directly into the
@@ -32,12 +32,10 @@ export function useRefToModel({ fieldName, modelName, refName }) {
nextRecord.update({ [fieldName]: ref });
}
});
const __destroy = component.__destroy;
component.__destroy = parent => {
onWillDestroy(() => {
const record = modelManager.models[modelName].get(component.props.localId);
if (record) {
record.update({ [fieldName]: clear() });
}
__destroy.call(component, parent);
};
});
}
@@ -2,7 +2,7 @@
import { Listener } from '@mail/model/model_listener';
const { onMounted, onPatched, useComponent } = owl;
const { onMounted, onPatched, onWillDestroy, onWillRender, useComponent } = owl;
/**
* This hooks provides support for accessing the values returned by the given
@@ -22,22 +22,16 @@ export function useRenderedValues(selector) {
name: `useRenderedValues() of ${component}`,
onChange: () => component.render(),
});
const __render = component.__render.bind(component);
component.__render = function () {
onWillRender(() => {
modelManager.startListening(listener);
renderedValues = selector();
modelManager.stopListening(listener);
return __render(...arguments);
};
})
onMounted(onUpdate);
onPatched(onUpdate);
function onUpdate() {
patchedValues = renderedValues;
}
const __destroy = component.__destroy;
component.__destroy = parent => {
modelManager.removeListener(listener);
__destroy.call(component, parent);
};
onWillDestroy(() => modelManager.removeListener(listener));
return () => patchedValues;
}
@@ -2,7 +2,7 @@
import { Listener } from '@mail/model/model_listener';
const { onMounted, onPatched, useComponent } = owl;
const { onMounted, onPatched, onWillDestroy, useComponent } = owl;
/**
* This hook provides support for executing code after update (render or patch).
@@ -29,11 +29,9 @@ export function useUpdate({ func }) {
}
onMounted(onUpdate);
onPatched(onUpdate);
const __destroy = component.__destroy;
component.__destroy = parent => {
onWillDestroy(() => {
if (modelManager) {
modelManager.removeListener(listener);
}
__destroy.call(component, parent);
};
});
}