Skip to content

Instantly share code, notes, and snippets.

@dominictarr
Created August 26, 2012 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dominictarr/3481264 to your computer and use it in GitHub Desktop.
Save dominictarr/3481264 to your computer and use it in GitHub Desktop.

what about this?

var olModel = new ObservableList()
var olWidget = observableWidget('#list_id', function (item) {
  return '<div id='+item.id+'>'+item.text+'</div>'
})
var remoteList = new RemoteList()

stream.pipe(remoteList).pipe(stream) //probably

//something like this?
sync(remoteList, olModel)
sync(olModel, olWidget)

lets just suppose that is the interface. what does sync look like? add and remove are easy, but move is more complicated.
you can use Array#spilce to represent all 3 (though, move is represented as a new insert)

one of the problems here is that there is a disjoin between Arrays, and HTMLElements which are a linked list. This is a benefit with crdt, actually because it has more linked list style behaviour (like pushing an item twice adds it to the end of the list, instead of duplicating it)

linked list behaviour is much easier to make concurrent updates to. but we don't have a Listish implementation that is separate to crdt, currently...

but it could be cleaner to approach it like that, rather building the List model into crdt.

@Raynos
Copy link

Raynos commented Aug 26, 2012

This is weird.

Try https://gist.github.com/3483305

@Raynos
Copy link

Raynos commented Aug 27, 2012

@dominictarr https://github.com/Raynos/element-list https://github.com/Raynos/splice-stream

As you mentioned move & sorting is harder and not quite implemented yet.

But you can create an ElementList which you can pipe elements into

var ElementList = require("element-list")

var listStream = ElementList(function (row, element) {
    element.id = item.id
    element.textContent = item.text
})

var set = doc.createSet("type", "messages")
    // implement set.createStream to return a splice stream
    , stream = set.createStream()

// pipe add / removal events from set into list stream
stream.pipe(listStream)

doc.set("_" + Date.now(), { type: "messages", text: "foobar" })

@Raynos
Copy link

Raynos commented Aug 27, 2012

@dominictarr.

cc @substack

The syncing of initial state is also a pain. Right now you can do, but that sync is kind of naive.

var set = someSet
    // if this is a splice stream instance then
    , stream = set.createStream()

// you can call sync
stream.sync(listStream)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment