Skip to content

Instantly share code, notes, and snippets.

@geta6
Last active December 28, 2015 15:49
Show Gist options
  • Save geta6/7524801 to your computer and use it in GitHub Desktop.
Save geta6/7524801 to your computer and use it in GitHub Desktop.
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