docs: function connect(config)
  {
  	config = config || {};
  
  	var url = new Url();
  
  	// Our ref used for example apps. Data may be cleared periodically.
  	var baseRefUrl = config.baseRefUrl || 'https://altspace-apps.firebaseio.com/apps/examples/';
  	var baseRef = new Firebase$1(baseRefUrl);
  
  	// Gather query paramaters (some may only be used as testing overrides)
  	var instanceId = config.instanceId || url.query['altspace-sync-instance'];
  	var spaceId = config.spaceId || url.query['altspace-sync-space'];
  	var userId = config.userId || url.query['altspace-sync-user'];
  
  	if (!config.appId || !config.authorId) {
  		throw new Error('Both the appId and authorId must be provided to connect.');
  	}
  
  	var tasks = [];
  	if (inAltspace) {
  		if (!spaceId) { tasks.unshift(altspace.getSpace()); }
  		if (!userId) { tasks.unshift(altspace.getUser()); }
  	}
  
  	var refs = {};
  	var projectId = getProjectId(config.appId, config.authorId, canonicalUrl);
  	refs.app = baseRef.child(projectId).child('app');
  	var instancesRef = refs.app.child('instances');
  	if(instanceId) {
  		refs.instance = instancesRef.child(instanceId);
  	}
  	else {
  		refs.instance = instancesRef.push();
  		instanceId = refs.instance.key();
  		url.query['altspace-sync-instance'] = instanceId;
  		window.location.href = url.toString();
  		// bail early and allow the page to reload
  		return Promise.reject(new Error('Sync instance id not found. Reloading app with new sync id.'));
  	}
  
  	return Promise.all(tasks).then(function (results) {
  		if (inAltspace) {
  			if (!spaceId) { spaceId = results.pop().sid; }
  			if (!userId) { userId = results.pop().userId; }
  		}
  
  		spaceId = dashEscape(spaceId);
  		userId = dashEscape(userId);
  		instanceId = dashEscape(instanceId);
  
  		refs.space = spaceId ? refs.app.child('spaces').child(spaceId) : null;
  		refs.user = userId ? refs.app.child('users').child(userId) : null;
  
  		var connection = refs;
  		return connection;
  	});
  }