-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feaure Request] implement a way to register a callback to be called when class is instantiated #5
Comments
Thanks for the request, totally makes sense :) |
Done, see https://github.com/zheksoon/dioma?tab=readme-ov-file#injection-hooks section of README |
Many thanks. Can you show me how can i get the instance and or the class using |
Sure! The descriptor is the object that was used in wild.register({ token: animalToken, class: Dog, scope: Scopes.Transient() }); So you can use |
Yes. To cover the use case i cited and covered by bottlejs#decorator. If i understand correct, Some notes:
|
Here's my concrete user case: Declare the class to be injected // @service register a class in the DI container
// @taskHandler register the method in the a property of class constructor to be used as event handlers
@service('schedulesStore', ['appStore'])
class SchedulesStore extends SchedulesQuery {
constructor(appStore) {
super()
bindRefParams(appStore, this, {
customerId: 'currentCustomer',
})
this.observe()
}
@taskHandler('save-schedule')
saveSchedule({model, attrs, dirtyAttrs}) {
if(model.isNew()) {
return this.create(attrs)
}
return model.save(dirtyAttrs, { patch: true })
}
}
export { SchedulesStore } start listening to the events // in the start of app
// bindClassTasks checks if there are handlers registered in constructor and configure the event listeners
registry.decorator((instance) => {
bindClassTasks(instance)
return instance
}) |
Ah, ok, I see. Will think about the implementation. But PRs are welcome! :) |
Bottlejs has a concept of decorator https://github.com/young-steveo/bottlejs?tab=readme-ov-file#decorators that is a function that runs when class / service is instantiated
Currently i use to register event handlers when a class declares one or more
The text was updated successfully, but these errors were encountered: