Created
October 20, 2014 17:46
-
-
Save miere/2dee5320743358958025 to your computer and use it in GitHub Desktop.
Hypothetical two-way binding API for improvement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div id="template"> | |
| <fieldset> | |
| <legend>New task</legend> | |
| <form> | |
| <input type="text" id="title" placeholder="Title" /> | |
| <input type="text" id="description" placeholder="Description" /> | |
| <button class="btn-primary btn-add">Adicionar</button> | |
| </form> | |
| </fieldset> | |
| <h2>My tasks</h2> | |
| <ul class="items"> | |
| <li> | |
| <span class="title"></span> | |
| <span class="description"></span> | |
| </li> | |
| </ul> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define([ "observable" ], function( observable ){ | |
| var todolist = { | |
| form: observable( "#template form" ).bindIds(), | |
| items: observable( "#template .items" ).forEach({ | |
| title: obseravable(".title"), | |
| description: obseravable( ".description" ) | |
| }), | |
| addItem: observable( "#template .btn-add" ).bind( "click", function( self ){ | |
| self.items.push({ | |
| item: self.form().title(), | |
| description: self.form().description() | |
| }) | |
| }) | |
| } | |
| return obserable( todolist ) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment