|
I missed my update last week, so this post actually covers the past two
weeks.
Rewrite with dijit._Widget
One of the first things Peter mentioned after my
initial commits was that my code was not very Dojo-like, and (though he
didn't say it) not very good. I had all the setup code in a single
initialization function, which the client had to explicitly call. Instead
of having a separate class for each component (Source, Canvas, Editor),
each piece was declared as a dojo.dnd.Source and then specific actions were
attached here, there, and anywhere. The code was not at all modular, with
the implementation exposed in many places. Peter gently suggested making
each component a subclass of dijit._Widget, which would give me a lot of
built-in functionality (dijit.byId,
constructors, etc.) for free.
Refactoring the code to subclass dijit._Widget has been very helpful. The
components are completely decoupled, my code is much more modular, and the
client code is quite simple. Creating a class for each component also makes
customizing their behavior a cinch, since it's easy to monkeypatch any of
the class methods.
PropEditor
I've finally created the PropEditor,
which allows you to edit the properties of a field element. Right now it
only supports changing the name, but eventually it will be able to edit the
choices for a select, change the default value for a field, and more.
pub/sub
I'm trying to keep the components completely decoupled after the
refactoring, so each piece is usable in isolation from the others. This
means that, for example, the Canvas can't
call a method of the PropEditor when a
field is selected, since there may not even be a PropEditor instance on the page. Instead of
direct method calls, I'm using dojo.publish + dojo.subscribe to pass messages and data around
to anyone who wants to listen. This is my first time doing event-driven
programming like this, and I think it's a neat way to maintain modularity
between classes. The PropEditor could
actually be used on any page that publishes the correct messages, not just
in concordance with my Canvas class.
Loading existing elements
Since I'm building a form editor, and not just a form creator,
the Canvas needs a way to load existing
form elements from a page. Taking a page from dojo.dnd.Source, the Canvas will now add any existing soc.ed.Elements to its internal structure when
the Canvas is created, similar to how
dojoDndItems are gathered.
All the major pieces of the editor have been created, so now I'll be
focused on making each one richer and better.
|