democracyworks / hat-trick

Hat Trick - Rails wizards done right
MIT License
5 stars 0 forks source link

Refactor set_contents functionality #3

Open cap10morgan opened 12 years ago

cap10morgan commented 12 years ago

The "set_contents" DSL method allows rendering a step on the server and sending it down to the client just in time for it to display. This has the advantage of being able to use information submitted in previous steps, which isn't otherwise possible because all the steps download to the client at the beginning of the wizard, so any just-in-time modifications have to be done via Javascript.

With i18n making it even more apparent that server-side rendering is the way to go (otherwise we'd have to have 2 different ways of doing i18n, which would be annoying), I think we should clean up and simplify the set_contents approach and make it the new way of working with hat-trick.

In order to do that, I want to get rid of set_contents and instead use a simpler "use_partial" method that will encapsulate more of the details. This will require refactoring the DSL a bit, though. The first thing I want to try is making the primary step block a "before" callback. This may have other nice side-effects for simplifying hat-trick's object model as well.

It will be a bit of work, but I think it will improve things quite a bit.

This feels like PJAX, so I should investigate that a bit too. Just to make sure I'm not badly re-inventing something for which there are already helpful libraries and/or best practices.