Skip to content

Instantly share code, notes, and snippets.

@lambdabaa
Last active December 16, 2015 16:19
Show Gist options
  • Save lambdabaa/5462724 to your computer and use it in GitHub Desktop.
Save lambdabaa/5462724 to your computer and use it in GitHub Desktop.
Super awesome cal sync interface
/**
* Called when we get events for the first time or when we get a delta.
* @param {Calendar.ResourceType} resourceType
* @param {Calendar.Resource.Authorizer} authorizer
* @param {Function} cb Will get called with Array.<Calendar.Resource>
*/
on = function(resourceType, authorizer, cb);
/**
* Unsubscribe.
* @param {Calendar.ResourceType} resourceType
* @param {Calendar.Resource.Authorizer} authorizer
* @param {Function} cb Will get called with Array.<Calendar.Resource>
*/
off = function(resourceType, authorizer, cb);
/**
* Update this resource.
* @param {Calendar.Resource} resource
* @param {Calendar.Resource.Authorizer} authorizer
* @param {Function} cb Will be called possibly with an error object.
* @return {Calendar.Resource.Pending}
*/
update = function(resource, authorizer, cb);
/**
* Delete this resource.
* @param {Calendar.Resource} resource
* @param {Calendar.Resource.Authorizer} authorizer
* @param {Function} cb Will be called possibly with an error object.
* @return {Calendar.Resource.Pending}
*/
delete = function(resource, authorizer, cb);
/** @constructor */
Calendar.Resource = function() {};
/** @constructor */
Calendar.Resource.Authorizer = function() {
...
};
/** @constructor */
Calendar.Resource.Pending = function() {};
Calendar.Resource.Pending.prototype = {
abort: function() {},
...
};
Calendar.ResourceType = {
CALENDARS: 'calendars',
EVENTS: 'events',
...
};
@lambdabaa
Copy link
Author

var accountList;
on(Calendar.Resource.ResourceType.ACCOUNTS, function(accounts) {
  accountList = accounts;
});


function createAccount() {
  var account = new Calendar.Resource.Account;
  accountList.addChild(account);
  update(accountList, new Calendar.Authorizer(credentials), function(accountList, err) {
  });

  // Then if another view was watching accounts, it would get pushed the new account list
}

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