Skip to content

Commit

Permalink
Refactor #3965 - Added hooks keyword to control all lifecycle metho…
Browse files Browse the repository at this point in the history
…ds to self/global PT options
  • Loading branch information
mertsincan committed Jul 4, 2023
1 parent d9baf29 commit 3442aca
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
30 changes: 30 additions & 0 deletions components/lib/basecomponent/BaseComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,40 @@ export default {
}
}
},
beforeCreate() {
this.pt?.hooks?.['beforeCreate']?.();
this.$primevue?.config?.pt?.[this.$.type.name]?.hooks?.['beforeCreate']?.();
},
created() {
this._hook('created');
},
beforeMount() {
loadBaseStyle();
this._hook('beforeMount');
},
mounted() {
this._hook('mounted');
},
beforeUpdate() {
this._hook('beforeUpdate');
},
updated() {
this._hook('updated');
},
beforeUnmount() {
this._hook('beforeUnmount');
},
unmounted() {
this._hook('unmounted');
},
methods: {
_hook(hookName) {
const selfHook = this._getOptionValue(this.pt, `hooks.${hookName}`);
const globalHook = this._getOptionValue(this.globalPT, `hooks.${hookName}`);
selfHook?.();
globalHook?.();
},
_getHostInstance(instance) {
return instance ? (this.$options.hostName ? (instance.$.type.name === this.$options.hostName ? instance : this._getHostInstance(instance.$parentInstance)) : instance.$parentInstance) : undefined;
},
Expand Down
4 changes: 2 additions & 2 deletions components/lib/basedirective/BaseDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ const BaseDirective = {
},
_hook: (directiveName, hookName, el, binding, vnode, prevVnode) => {
const config = binding?.instance?.$primevue?.config;
const globalHook = config?.pt?.directives?.[directiveName]?.hooks?.[hookName];
const selfHook = binding?.value?.pt?.hooks?.[hookName];
const globalHook = config?.pt?.directives?.[directiveName]?.hooks?.[hookName];

globalHook?.(el, binding, vnode, prevVnode);
selfHook?.(el, binding, vnode, prevVnode);
globalHook?.(el, binding, vnode, prevVnode);
},
_extend: (name, options = {}) => {
const handleHook = (hook, el, binding, vnode, prevVnode) => {
Expand Down

0 comments on commit 3442aca

Please sign in to comment.