Skip to content

Instantly share code, notes, and snippets.

@gr2m
Last active August 29, 2016 09:01
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gr2m/5463525 to your computer and use it in GitHub Desktop.
Save gr2m/5463525 to your computer and use it in GitHub Desktop.
Imagine you could share user data with JavaScript right in the browser. How would the code look like? This is what I came up with. Forks & comments much appreciated! (see also: https://gist.github.com/gr2m/5463475) #nobackend #dreamcode
// add a new share
share = new Share()
// grant / revoke access
share.grantReadAccess()
share.grantWriteAccess()
share.revokeReadAccess()
share.revokeWriteAccess()
share.grantReadAccess('joe@example.com')
share.revomeWriteAccess(['joe@example.com', 'lisa@example.com'])
// add all todo objects to the share
store.findAll('todo').then(share.add)
// remove a specific todo from the share
store.find('todo', '123').then(share.remove)
// remove objects from all shares
store.findAll('todo').then(share.remove)
// remove share
share.destroy()
// open a share and load all its objects
share = new Share('shareIdHere')
share.findAll().done( render )
// subscribe: sync changes between local store and remote share
share.subscribe()
share.unsubscribe()
@aishwar
Copy link

aishwar commented Nov 15, 2013

This looks cool. I am curious how would shares work. Would a share just be an object that contains pointers to data objects? Or would the actual data object be copied into the share?

@zerotacg
Copy link

in a talk [1] someone from hoodie mentioned that they share the data using filtered replication of couchdb

[1] https://www.youtube.com/watch?v=-x3Q61dBAwk#t=1770

@gr2m
Copy link
Author

gr2m commented Jan 19, 2015

I've updated the code to be generic

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