Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed list emitter mixin

  • Loading branch information...
commit 8a15048ba28c7d2df2a79906dea6ab128bb7d0ea 1 parent ee9a024
@matthewmueller authored
Showing with 21 additions and 11 deletions.
  1. +1 −1  component.json
  2. +6 −1 list.js
  3. +14 −9 test/index.html
View
2  component.json
@@ -6,7 +6,7 @@
"keywords": [],
"dependencies": {
"component/jquery" : "*",
- "matthewmueller/emitter" : "*"
+ "component/emitter" : "*"
},
"development" : {
"matthewmueller/hogan" : "*"
View
7 list.js
@@ -17,13 +17,18 @@ module.exports = List;
function List() {
if(!(this instanceof List)) return new List;
- Emitter.call(this);
this.items = {};
this.cid = 0;
this.el = $('<ul class="list">');
}
/**
+ * Mixin `Emitter`
+ */
+
+Emitter(List.prototype);
+
+/**
* Add templating
*
* @return {List}
View
23 test/index.html
@@ -7,18 +7,23 @@
<h2>List Component</h2>
<script src="../build/build.js" type="text/javascript"></script>
<script type="text/template" id="message">
- <a href='#'>
- <span class='from'>{from}</span>
- <span class='subject'>{subject}</span>
- <span class='message'>{message}</span>
- </a>
+ <div class="message">
+ <a href='#'>
+ <span class='from'>{{from}}</span>
+ <span class='subject'>{{subject}}</span>
+ <span class='message'>{{message}}</span>
+ </a>
+ </div>
</script>
<script type="text/javascript">
var List = require('list'),
+ hogan = require('matthewmueller-hogan'),
+ str = document.getElementById('message').text,
+ tpl = hogan.compile(str),
inbox = new List;
- inbox.template(document.getElementById('message').text)
+ inbox.template(tpl);
var messages = [
{ from : 'jim', subject : 'hey', message : 'blah'},
@@ -26,9 +31,9 @@
{ from : 'drew', subject : 'howdy', message : 'yah'},
]
- inbox.add(messages, function(message) {
- console.log('invoked fn', message);
- })
+ messages.forEach(function(message) {
+ inbox.add(message, function(m) { console.log('invoked fn', m); })
+ });
inbox.el.appendTo('body');
Please sign in to comment.
Something went wrong with that request. Please try again.