Uniform is a view model for CoffeeScript
Uniform is a way of organising your front-end CoffeeScript. You describe individual components of your application as Uniform classes. They can be used for delegating events, describing behaviour and handle the building of elements.
For example a contact form could have AJAX behaviour described as a Uniform class.
# Let's describe a contact form# The HTML template: built """<form><textarea></textarea><button>Send</button></form>"""# We cache some children to properties on this object:add'msg''textarea'add'btn''button'# We delegate the submit event to @sendResponse():# attach submit event to @eladd 'submit'epreventDefault@send_response# Do the sending :): ->@btntext'Sending...'$post 'index.html'msg: @msg=>@msgval''@btntext'Send'# InitialisejQuery ->form =$'body'appendformel
You can also use your view models on elements already in the DOM like so:
# Or use on an existing elementjQuery -> el: $'#contact'
Uniform is best used in compiled CoffeeScript browser environments. Since Uniform is a CoffeeScript class it is easiest to extend and use it if your front end code is also CoffeeScript.
Use it how you like though.
You can simply use the JS found in the
dist folder of the
Uniform git repo https://github.com/DrPheltRight/uniform.
Clone the repository https://github.com/DrPheltRight/uniform.git and then run "cake build" to make a fresh copy of Uniform.
v0.5.x will see the introduction of a JS interface for Uniform. A current example can be found in: https://github.com/DrPheltRight/uniform/blob/develop/examples/js-example/todo.js
Since we have added the add() syntax for events we can now remove the need for a blank string to indicate placing the listening directly on @el. The only thing that would break is the object syntax which as of v0.5.x is deprecated and will be remove in v0.6.x. So as of v0.6.x I will: