refactor: implement state proxy in partner list patch and remove unnecessary xml asset registration
This commit is contained in:
parent
2823d613a8
commit
095f87d8b9
@ -23,7 +23,6 @@ Custom POS Loyalty and Membership management features:
|
|||||||
],
|
],
|
||||||
'assets': {
|
'assets': {
|
||||||
'point_of_sale._assets_pos': [
|
'point_of_sale._assets_pos': [
|
||||||
'pos_loyalty_member_custom/static/src/app/screens/partner_list_patch.xml',
|
|
||||||
'pos_loyalty_member_custom/static/src/app/screens/partner_list_patch.js',
|
'pos_loyalty_member_custom/static/src/app/screens/partner_list_patch.js',
|
||||||
'pos_loyalty_member_custom/static/src/app/models/pos_order_patch.js',
|
'pos_loyalty_member_custom/static/src/app/models/pos_order_patch.js',
|
||||||
]
|
]
|
||||||
|
|||||||
@ -7,24 +7,46 @@ import { normalize } from "@web/core/l10n/utils";
|
|||||||
patch(PartnerList.prototype, {
|
patch(PartnerList.prototype, {
|
||||||
setup() {
|
setup() {
|
||||||
super.setup(...arguments);
|
super.setup(...arguments);
|
||||||
this.state.inputQuery = "";
|
const realState = this.state;
|
||||||
|
this.realState = realState;
|
||||||
|
this.inputQuery = "";
|
||||||
|
|
||||||
|
this.state = new Proxy(realState, {
|
||||||
|
get: (target, prop, receiver) => {
|
||||||
|
if (prop === "query") {
|
||||||
|
// Access target.query to register dependency for reactivity when needed
|
||||||
|
const _unused = target.query;
|
||||||
|
return this.inputQuery;
|
||||||
|
}
|
||||||
|
return Reflect.get(target, prop, receiver);
|
||||||
|
},
|
||||||
|
set: (target, prop, value, receiver) => {
|
||||||
|
if (prop === "query") {
|
||||||
|
this.inputQuery = value;
|
||||||
|
if (!value && target.query !== "") {
|
||||||
|
target.query = "";
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return Reflect.set(target, prop, value, receiver);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this._filteredLoyaltyCache = new Map();
|
this._filteredLoyaltyCache = new Map();
|
||||||
this._partnersSearchCache = new Map();
|
this._partnersSearchCache = new Map();
|
||||||
},
|
},
|
||||||
|
|
||||||
onInputQueryChange(newValue) {
|
|
||||||
if (!newValue) {
|
|
||||||
this.state.query = "";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async searchPartner() {
|
async searchPartner() {
|
||||||
this.state.query = this.state.inputQuery || "";
|
if (this.realState) {
|
||||||
|
this.realState.query = this.inputQuery || "";
|
||||||
|
}
|
||||||
return super.searchPartner(...arguments);
|
return super.searchPartner(...arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
async onEnter() {
|
async onEnter() {
|
||||||
this.state.query = this.state.inputQuery || "";
|
if (this.realState) {
|
||||||
|
this.realState.query = this.inputQuery || "";
|
||||||
|
}
|
||||||
return super.onEnter(...arguments);
|
return super.onEnter(...arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user