Last active
December 28, 2015 15:49
-
-
Save geta6/7524801 to your computer and use it in GitHub Desktop.
This file contains 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
class Item extends Backbone.Model | |
default: { user: null, message: null } | |
class ItemView extends Backbone.View | |
tagName: 'div' | |
template: _.template "<div class='user'><%- user %></div><div class='message'><%- message %></div>" | |
render: -> | |
@$el.addClass('item').html @template @model.toJSON() | |
return @ | |
class Items extends Backbone.Collection | |
model: Item | |
items = new Items | |
class ItemsView extends Backbone.View | |
el: $ '#items' | |
initialize: (@collection) -> | |
@collection.each (item) => @append item | |
@listenTo @collection, 'add', @append | |
append: (item) -> | |
@$el.prepend (new ItemView model: item).render().el | |
tuple = [decodeURIComponent window.location.pathname.split('/')[1]] | |
(linda = new Linda).io.on 'connect', -> | |
ts = new linda.TupleSpace 'homeboard' | |
ts.watch tuple, (tuple) -> | |
if 1 < tuple[1].length | |
items.add new Item | |
message: tuple[1] | |
user: if tuple[2]? then tuple[2] else null | |
$ -> new ItemsView items |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment