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
3.0: Model.initialize event (originally: Apply Events to TableRegistry) #4796
Comments
What kind of changers would you apply? |
For example I'd like to load some behaviors to every table in my app. |
You can make an |
@ADmad , I can't do that with plugin tables. Or do that from a plugin scope. |
I guess we should just make |
But that's not the point. The point is to have some control over table creation. TableRegistry is static and it's really hard to hook into it. Besides having an AppTable wouldn't help to attach behaviors from plugin scope. |
I guess we could have an initialize event like controllers do |
This doesn't seem unreasonable to me. What would you call the event? |
Table.initialize or just Model.initialize to make it similar to the rest |
Model.initialize sounds good. If I'm not mistaken this event could be dispatched by Table itself and could be easely "fetched" by an EventManager singleton? |
Firing the event from the table is far more palatable than from the registry. In that case I would go with 'Model.initialize'. |
So what about |
No, the method should stay the same. And the event should be called after that method |
@lorenzo That would make |
@ADmad - this is my point. |
Not the only method. The Controller::initialize() method works the same. I see those initialize() methods as simpler ways too add constructor logic. |
But |
But we have Isn't that a bit messy? |
@robertpustulka Yeah, |
If anything is messy it is the component method. I think the initialize() as a constructor hook is a nicer pattern to follow than the event based one. Perhaps we should make the component method follow the controller workflow, and not have a Controller.initialze event listener on Component by default? |
@markstory That sounds reasonable. |
But it still leaves |
The beforeFilter method must be called before the startup event, or many workflows around component setup will no longer work. |
Closing, as there is a pull request up now that we can discuss further. |
I was wondering if there could be some way of observing Table creation process.
ie: after every new Table object TR could dispatch an event (using global EventManager) allowing an app or a plugin to hook into this Table and do some stuff with it. This could be helpful if we wanted to apply some changes to every table in registry upon their creation.
I'm not sure it feels right, so I open this for discussion for now.
The text was updated successfully, but these errors were encountered: