Permalink
Browse files

cell types

  • Loading branch information...
1 parent 54e7c96 commit 781b7862ab190dc43b8b896e4f8f46c81b724685 @rranshous committed May 31, 2012
Showing with 102 additions and 74 deletions.
  1. +38 −22 scripts/cell.coffee
  2. +39 −20 scripts/cell.js
  3. +13 −0 scripts/memory_cell.coffee
  4. +8 −8 simpleserver.coffee
  5. +4 −24 simpleserver.js
View
@@ -5,8 +5,6 @@ define ['spine'], (spine) ->
@extend Spine.Events
constructor: (@id) ->
- # note our data
- @data = {}
# store a lookup of when it was set
@tokens = {}
@@ -17,33 +15,42 @@ define ['spine'], (spine) ->
# sets the cell's value
# if token is set only sets if given token
# is greater than the stored token
- set: (key, value, token, fire = true) ->
+ set: (key, value, token, fire = true, callback= ->) ->
console.log "cell [set] #{key} #{value} #{token} #{fire}"
- # set the new value
- @data[key] = value
-
# if token is given and older, we're done
- return unless token? or token > @tokens[key]
+ unless token? or token > @tokens[key]
+ # call back w/ success being false
+ callback false, key, value
+ return
# generate a new token for this set op
token = @tokens[key] = @_new_token_id()
- # let the world know
- if fire
- console.log "cells firing set_cell_value"
- @trigger 'set_cell_value',
- key: key,
- value: value,
- token: token
+ # actually set the data
+ @_set key, value, ->
+
+ # let the world know
+ if fire
+ console.log "cells firing set_cell_value"
+ @fire 'set_cell_value',
+ key: key,
+ value: value,
+ token: token
+
+ # call back with much success
+ callback true, key, value
+
+ _set: (key, value, callback= ->) ->
+ callback true, key, value
# gets a value from the
get: (key) ->
@data[key]
# sets multiple values
- set_data: (data) ->
+ set_data: (data, callback= ->) ->
# this can't be used for clearning
unless data?.length
@@ -52,14 +59,23 @@ define ['spine'], (spine) ->
# generate token
token = @_new_token_id()
- # update ourself, don't emit
- @set k, v, token, false for k, v of data
+ # keep track of how many set's we've done
+ total = data.length
+ done = 0
- # let the world know
- @trigger 'set_cell_data',
- id: @id,
- data: data,
- token: token
+ # update ourself, don't emit
+ @set k, v, token, false, (success, key, value) ->
+ done += 1
+
+ # did we finish ?
+ if total == done
+ callback true, data
+
+ # let the world know
+ @fire 'set_cell_data',
+ id: @id,
+ data: data,
+ token: token
# clears all the cell's values
clear: () ->
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -0,0 +1,13 @@
+
+define ['cell'], (Cell) ->
+
+ class MemoryCell extends Cell
+
+ constructor: () ->
+ # store our cell's values
+ @data = {}
+ super arguments
+
+ _set: (key, value, callback= ->) ->
+ @data[key] = value
+ callback true, key, value
View
@@ -1,26 +1,26 @@
+
+requirejs = require('requirejs')
+
+requirejs ['spine', 'socket.io', 'express','mediator', 'cell' ],
+(spine, io, express, mediator, cell) ->
+
+#### HOSTING #####
# Web server
-io = require 'socket.io'
-express = require 'express'
app = express()
server = app.listen 8080
# host our statics
#console.info "making static #{__dirname + '/'}"
app.use express.static __dirname + '/'
# socket IO layer
io = io.listen server
+#### END HOSTING ####
# helper method for cell ids
last_cell_id = 0
next_cell_id = ->
last_cell_id += 1
last_cell_id
-Spine = require 'spine'
-class CellsLookup extends Spine.Module
- @include Spine.Events
-cells = new CellsLookup()
-
-
# set single cell value
# callback: id, key, value, old_value
set_cell_value = (id, key, value, emit, callback) ->
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 781b786

Please sign in to comment.