So having fun adding the ability to cope with multiple commands in my command line interface - and since I know this is an early spike to get it moving I can do things that make the code functional, but also pretty ugly.
There's a few things already need fixing (some would argue I should have done them before doing anything, but I find it becomes a barrier if I try too early):
- put some TDD in place, theres only ~80 odd lines of code so its still easy to do
- make the code more structured (in JS land that means more objects)
- separate the UI code from the logic code - so how to add a new command entry vs how to render it in HTML
One approach I like is not having lots of HTML element creation code, and a neat way round this is to clone an existing node - it probably should be a
UI pattern in JavaScript. So in the example of a command line interface, where each new entry is very similar - rather than having lots of code to recreate the same structure each time: you can simply clone the first node at load time - and then clone that each time to add the same type of HTML item (with children). This also abstracts the HTML structure away from the code, so its easier to evolve the structure and appearance separate from the code. This approach can be generalized for most interfaces with multiple items that are the same (so notes, entities etc) - with the prototype UI object either being the first blank item, or hidden.
So next is probably a bit of refactoring for TDD - and I guess that means I need to find a good TDD library (and good for me means very simple and no dependencies on JQuery etc)
No comments:
Post a Comment