The todo model uses the acts_as_state_machine plugin which makes it
possible to run code at specific events, e.g. when entering completed
state, the completed_at field is set by the state machine model itself
in the entry action.
http://github.com/bohrax/tracks/blob/4497b597e3d090fbc3cffd809320de68e7c2894c/app/models/todo.rb#L31

I think it would be good to add more functionality in the state
machine model, which is directly related to state changes in order to
prevent duplication of this code in the controller.

An example is when completing an action. This (now) requires checking
if there are pending actions that should be activated. If this
behavior was added to the model itself, it would not require these
(duplicated) checks in the controller code:
http://github.com/bohrax/tracks/blob/4497b597e3d090fbc3cffd809320de68e7c2894c/app/controllers/todos_controller.rb#L169
http://github.com/bohrax/tracks/blob/4497b597e3d090fbc3cffd809320de68e7c2894c/app/controllers/todos_controller.rb#L270

The main problem with this approach is that I don't know how to get
data out of the state machine and into the javascript code. Ideally
I'd like to trigger javascript updates from the state machine
transitions.

It seems to me that the current ajax javascripts are trying to
anticipate model state changes and remake the GUI after that. I
imagine that using FSM state transitions to trigger "the actual
updates" would lead to simpler and more maintainable code.


Any thoughts? Please let me know if you want more details and I'll try
to explain better.

/Henrik

On Mon, Jul 20, 2009 at 10:14 AM, Reinier Balt<[email protected]> wrote:
> I don't know what you mean. Could you be more specific?
>
> Reinier
>
>> -----Oorspronkelijk bericht-----
>> Van: [email protected] [mailto:tracks-
>> [email protected]] Namens Henrik Bohre
>> Verzonden: zondag 19 juli 2009 19:20
>> Aan: tracks-discuss
>> Onderwerp: [Tracks-discuss] Discussion of state machine usage in Tracks
>> code
>>
>> Hi all,
>>
>> When trying to DRY up some code I realized that e.g. completing a todo
>> from the normal view and the mobile view requires running
>> completion/activation code on both todos_controller#toggle_check and
>> todos_controller#update.
>>
>> I was thinking that it would be nice to add this to the state machine
>> in the todo model instead, so the model would always be consistent.
>> The problem I face now is how to get information from the state
>> changes in the model to the ajax javascripts.
>>
>> Is this a known problem, and the reason it is not used like this?
>>
>>
>> Best regards,
>> /Henrik
>> _______________________________________________
>> Tracks-discuss mailing list
>> [email protected]
>> http://lists.rousette.org.uk/mailman/listinfo/tracks-discuss
>
>
_______________________________________________
Tracks-discuss mailing list
[email protected]
http://lists.rousette.org.uk/mailman/listinfo/tracks-discuss

Reply via email to