mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-31 07:32:59 +00:00 
			
		
		
		
	Simplify syncer interface
This commit is contained in:
		| @@ -64,11 +64,12 @@ exports.startup = function() { | |||||||
| 			$tw.modal.display(event.param); | 			$tw.modal.display(event.param); | ||||||
| 		},false); | 		},false); | ||||||
| 		// Install the syncer message mechanism | 		// Install the syncer message mechanism | ||||||
| 		var handleSyncerEvent = function(event) { | 		document.addEventListener("tw-login",function(event) { | ||||||
| 			$tw.wiki.handleSyncerEvent.call($tw.wiki,event); | 			$tw.wiki.invokeSyncers("handleLoginEvent",event); | ||||||
| 		}; | 		},false); | ||||||
| 		document.addEventListener("tw-login",handleSyncerEvent,false); | 		document.addEventListener("tw-logout",function(event) { | ||||||
| 		document.addEventListener("tw-logout",handleSyncerEvent,false); | 			$tw.wiki.invokeSyncers("handleLogoutEvent",event); | ||||||
|  | 		},false); | ||||||
| 		// Install the scroller | 		// Install the scroller | ||||||
| 		$tw.pageScroller = new $tw.utils.PageScroller(); | 		$tw.pageScroller = new $tw.utils.PageScroller(); | ||||||
| 		document.addEventListener("tw-scroll",$tw.pageScroller,false); | 		document.addEventListener("tw-scroll",$tw.pageScroller,false); | ||||||
|   | |||||||
| @@ -627,20 +627,11 @@ exports.initServerConnections = function() { | |||||||
| /* | /* | ||||||
| Invoke all the active server connections | Invoke all the active server connections | ||||||
| */ | */ | ||||||
| exports.invokeServerConnections = function(method /* ,args */) { | exports.invokeSyncers = function(method /* ,args */) { | ||||||
| 	var args = Array.prototype.slice.call(arguments,1); | 	var args = Array.prototype.slice.call(arguments,1); | ||||||
| 	for(var title in this.serverConnections) { | 	for(var name in this.syncers) { | ||||||
| 		var connection = this.serverConnections[title]; | 		var syncer = this.syncers[name]; | ||||||
| 		connection.syncer[method].apply(connection.syncer,[connection.connection].concat(args)); | 		syncer[method].apply(syncer,args); | ||||||
| 	} |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| /* |  | ||||||
| Handle a syncer message |  | ||||||
| */ |  | ||||||
| exports.handleSyncerEvent = function(event) { |  | ||||||
| 	for(var syncer in this.syncers) { |  | ||||||
| 		this.syncers[syncer].handleEvent(event); |  | ||||||
| 	} | 	} | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @@ -658,7 +649,7 @@ exports.getTiddlerText = function(title,defaultText) { | |||||||
| 		return tiddler.fields.text; | 		return tiddler.fields.text; | ||||||
| 	} else { | 	} else { | ||||||
| 		// Ask all the server connections to load the tiddler if they can | 		// Ask all the server connections to load the tiddler if they can | ||||||
| 		this.invokeServerConnections("lazyLoad",title,tiddler); | 		this.invokeSyncers("lazyLoad",title,tiddler); | ||||||
| 		// Indicate that the text is being loaded | 		// Indicate that the text is being loaded | ||||||
| 		return null; | 		return null; | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -78,24 +78,10 @@ TiddlyWebSyncer.prototype.addConnection = function(connection) { | |||||||
| 	return ""; // We only support a single connection | 	return ""; // We only support a single connection | ||||||
| }; | }; | ||||||
|  |  | ||||||
| /* |  | ||||||
| Handle syncer messages |  | ||||||
| */ |  | ||||||
| TiddlyWebSyncer.prototype.handleEvent = function(event) { |  | ||||||
| 	switch(event.type) { |  | ||||||
| 		case "tw-login": |  | ||||||
| 			this.promptLogin(); |  | ||||||
| 			break; |  | ||||||
| 		case "tw-logout": |  | ||||||
| 			this.logout(); |  | ||||||
| 			break; |  | ||||||
| 	} |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| /* | /* | ||||||
| Lazily load a skinny tiddler if we can | Lazily load a skinny tiddler if we can | ||||||
| */ | */ | ||||||
| TiddlyWebSyncer.prototype.lazyLoad = function(connection,title,tiddler) { | TiddlyWebSyncer.prototype.lazyLoad = function(title,tiddler) { | ||||||
| 	// Queue up a sync task to load this tiddler | 	// Queue up a sync task to load this tiddler | ||||||
| 	this.enqueueSyncTask({ | 	this.enqueueSyncTask({ | ||||||
| 		type: "load", | 		type: "load", | ||||||
| @@ -149,7 +135,7 @@ TiddlyWebSyncer.prototype.getStatus = function(callback) { | |||||||
| /* | /* | ||||||
| Dispay a password prompt and allow the user to login | Dispay a password prompt and allow the user to login | ||||||
| */ | */ | ||||||
| TiddlyWebSyncer.prototype.promptLogin = function() { | TiddlyWebSyncer.prototype.handleLoginEvent = function() { | ||||||
| 	var self = this; | 	var self = this; | ||||||
| 	this.getStatus(function(isLoggedIn,json) { | 	this.getStatus(function(isLoggedIn,json) { | ||||||
| 		if(!isLoggedIn) { | 		if(!isLoggedIn) { | ||||||
| @@ -203,7 +189,7 @@ TiddlyWebSyncer.prototype.login = function(username,password,callback) { | |||||||
| /* | /* | ||||||
| Attempt to log out of TiddlyWeb | Attempt to log out of TiddlyWeb | ||||||
| */ | */ | ||||||
| TiddlyWebSyncer.prototype.logout = function(options) { | TiddlyWebSyncer.prototype.handleLogoutEvent = function(options) { | ||||||
| 	options = options || {}; | 	options = options || {}; | ||||||
| 	this.log("Attempting to logout"); | 	this.log("Attempting to logout"); | ||||||
| 	var self = this, | 	var self = this, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jeremy Ruston
					Jeremy Ruston