For the last 7 years I’ve worked with User Experience designers and I have a huge respect for their craft. I’m also loving how designers are embracing HTML5 and CSS3, and how it is giving them ownership over the experience.
It’s affording deep collaboration between the designer and developer, and asserting the need for frameworks and tools to play to our respective crafts, and to be sensitive to the designer-developer-workflow.
With this in mind I struggled for a while with Ember. I wanted a clean separation between my HTML and my code. Ideally I didn’t want to change the HTML, and I really didn’t want to pollute it with proprietary code belonging to Ember (or any other framework).
I was really disappointed as the only solution offered up was to use Ember.TextField.
From:
<input type="text" id="firstName" placeholder="First" autofocus required>
To:
{{view Ember.TextField valueBinding="firstName"}}
It breaks the clean separation between designer and developer. It makes my code difficult to maintain. I loose the expressiveness of HTML5. Why?
I get the binding goodness it may bring, but…
At this point I did consider walking away from Ember, but I did persevere. In the end I opted to use plain old JQuery in my code. I’m intrigued to see how this plays out as I grow my codebase, but in the meantime it keeps my HTML as pure as it can be.
HTML:
<script type="text/x-handlebars" data-template-name="registration">
<form autocomplete="on" id="registration" {{action createUser on="submit"}}>
<label>Name</label>
<input type="text" id="firstName" placeholder="First" autofocus required>
<input type="text" id="lastName" placeholder="Last" required>
<label>Email</label>
<input type="email" id="primaryEmailAddress" placeholder="hello@mydomain.com" autocomplete="on" required><br>
<label>Password <em>Minimum 6 characters</em></label>
<input type="password" id="password" autocomplete="off" required pattern=".{6,}" title="Passwords must have a minimum of 6 characters."><br>
<input type="submit" value="Create account" onmouseup="form.className='submitted';" />
</form>
</script>
JavaScript:
App.UsersController = Ember.ObjectController.extend({
createUser : function () {
'use strict';
var user = App.User.createRecord({
firstName : $("#firstName").val(),
lastName : $("#lastName").val(),
primaryEmailAddress : $("#primaryEmailAddress").val(),
password : $("#password").val()
});
}
});
Hey Peter
Congrats on the move across to Microsoft. Hope all is well with you.
Have you looked at AngularJS? It allows for the kind of separation that you’re looking for.
In your instance, it would be (using square brackets for comment-friendly markup):
[input type=”text” id=”firstName” placeholder=”First” autofocus required ng-model=”firstName”]
That’s it — just plain ‘ol HTML, with a smidge of additional markup to describe what to bind to — very designer friendly, and promotes strong seperation of concerns between view and logic.
It’s also very test-friendly.
Cheers
Marty
Hey Marty, thanks for the note. It’s good to hear from you. I’ve looked at Angular, but I’ve not tried it in anger yet. You’ve given me the push to look again. I’ve heard it’s slow and causes performance to degrade as an app grows – is this your experience?
Cheers
Peter
I’m using Angular on a non-trivial single-page-app, and haven’t seen any performance issues yet — though it’s still early-ish days.
I get the feeling there’s a bit of FUD out there between JS frameworks. I certainly haven’t hit any issues that’s caused me to consider writing ‘performant’ versions of my code.
There’s a couple of good posts on the topic worth a read (in your stacks of free time 🙂
http://stackoverflow.com/questions/9682092/databinding-in-angularjs/9693933#9693933
http://stackoverflow.com/questions/11458436/angular-js-backbone-js-or-which-has-better-performance
Thanks for the links!
Loving Angular. I’ve done in 3 hours what it took me a week to achieve in Ember. It’s not invasive on the HTML. The separation of concerns and responsibilities is excellent. The learning curve is fairly straightforward and the documentation was helpful. SOLD!
Awesome! Glad it’s working for you — it’s made my transition from Flex -> HTML5 really enjoyable.