yohang / Finite

A Simple PHP Finite State Machine
http://yohan.giarel.li/Finite
MIT License
1.31k stars 188 forks source link

[Bundle] Lazy load loaders' callbacks #47

Closed winzou closed 10 years ago

winzou commented 10 years ago

To have callbacks instantiated only when they are to be called.

The approach I had with the CompilerPass before was not wrong, but it had the disadvantage of instantiate all callbacks when the Loader was loaded. This PR avoid this, and makes the callbacks instantiated only when a transition is applied and the callback is to be called.

yohang commented 10 years ago

Hi,

Is the callback instantiation overhead so important ? Even with the lazy instantiation ? There is only a proxy instantiated, no ?

winzou commented 10 years ago

The lazy option just avoids the loading of every loaders when you instantiate your state machine factory. TThis PR avoids the loading of every callbacks when you instantiate your state machine. And yes, loading all callbacks just to call a can, it's not good pattern.