Using @extend for new type of model storage

28 views
Skip to first unread message

Ioannis Latousakis

unread,
Jul 9, 2013, 12:29:20 PM7/9/13
to spi...@googlegroups.com
I am extending an application that works using Spine.Model.Local in order to support google drive realtime docs. 

I have completed the code that takes care of this process. Now I want to add it on any Model using a process same as @extend Spine.Model.Local.

The code I need to have only listens for events, and is not actually extending any existing Model methods. It looks like this:


rtc = require('rtc')

Spine.Model.Realtime = 
  @bind('update',rtc.saveJSON)
  @bind('destroy',rtc.deleteJSON) //< SyntaxError: Coffeescript Error: unexpected TERMINATOR when I dont intend on same level with Spine.mode.realtime
  Spine.bind("Model:fileUpdate",(event) -> modelMapUpdate(event))
  Spine.bind('Model:fileLoad',(map) -> loadModelMap(map)) 


Then I have defined two functions as well as an external JS file (rtc).

My problem is how I can add this to any Model class I need using the @extend, or something similar?

p.s I tried placing Spine.Mode.Realtime in node_modules/spine/src/ but it did not work. I am getting Uncaught Error: extend(obj) requires obj.
Also I keep getting this error : SyntaxError: Coffeescript Error: unexpected TERMINATOR  

p.s II: The above code works fine when its part of a Model class. I just need to take it out so that its reusable.

Ioannis Latousakis

unread,
Jul 9, 2013, 12:40:44 PM7/9/13
to spi...@googlegroups.com

Miles Matthias

unread,
Aug 5, 2013, 5:04:54 PM8/5/13
to spi...@googlegroups.com
I'm also looking to do something similar. I'm looking to create a model adaptor that uses both localStorage and Ajax. I'm also getting the same error you are.

Have you made any progress or updates on this? I saw you removed your SO question.

Ioannis Latousakis

unread,
Aug 5, 2013, 5:10:16 PM8/5/13
to spi...@googlegroups.com
I did not spent much time trying to do this. Instead I placed Spine.Model.Realtime inside my models folder. I just had to include it in my setup.coffee file found in app/lib and it works as expected. It would be better having it within the Spine folder but its not essential for me.

Ioannis Latousakis

unread,
Aug 5, 2013, 5:13:13 PM8/5/13
to spi...@googlegroups.com
My extension follows the same format as Local:

rtc = require("models/rtc")

Spine.Model.Realtime =
  extended:->
    @bind('update',rtc.updateJSON)
    @bind('create',rtc.createJSON)
    @bind('destroy',rtc.deleteJSON)

    Spine.Model.bind('Model:fileLoad',(map) =>
      @loadModelMap(map))

    Spine.Model.bind("Model:fileUpdate",(event) =>
      @modelMapUpdate(event))
     
    @idCounter = Math.random()


  loadModelMap: (map) ->
    ...

  modelMapUpdate: (event) ->
    ...
 

module?.exports = Spine.Model.Realtime

Miles Matthias

unread,
Aug 5, 2013, 5:19:04 PM8/5/13
to spi...@googlegroups.com
Thanks for the feedback, I'll let you know how it goes. I think a localStorage + Ajax adaptor would be commonly used so maybe the one I write can be pull-requested into the framework for others to use, but your Google Drive adaptor looks really cool too and I'd love to see it open sourced. A list of known model adaptors with github links on the spine site would be awesome to see too.

Miles Matthias

unread,
Dec 5, 2013, 5:52:19 PM12/5/13
to spi...@googlegroups.com
I ended up not doing this. I used the localStorage adaptors and created a sync manager to loop and update the server with local records.
Reply all
Reply to author
Forward
0 new messages