From 4012d388f4e4698ac13e30f0d8d3c310cdfe55d5 Mon Sep 17 00:00:00 2001 From: suVene Date: Mon, 8 Dec 2008 18:04:17 +0000 Subject: *SubjectHttp定義. *registerするときに下位クラスから基底クラスを指定するように変更. *notifier/observer/subject の PLUGIN_INFO対応 @see http://coderepos.org/share/browser/lang/javascript/vimperator-plugins/trunk/pluginManager.js *ほか. git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@26152 d0d07461-0603-4401-acd4-de1884942a52 --- notifier.js | 185 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 160 insertions(+), 25 deletions(-) (limited to 'notifier.js') diff --git a/notifier.js b/notifier.js index 126c523..5dcdfe5 100644 --- a/notifier.js +++ b/notifier.js @@ -1,22 +1,112 @@ -/** - * ==VimperatorPlugin== - * @name notifier.js - * @description notice of change framework. - * @description-ja 変更通知フレームワーク。 - * @author suVene suvene@zeromemory.info - * @version 0.1.0 - * @minVersion 2.0pre - * @maxVersion 2.0pre - * Last Change: 07-Dec-2008. - * ==/VimperatorPlugin== - * - * HEAD COMMENT {{{ - * }}} - */ +// PLUGIN_INFO//{{{ +var PLUGIN_INFO = + + {name} + notice of change framework. + 変更通知フレームワーク。 + suVene + 0.1.0 + 2.0pre + 2.0pre + +; +//}}} (function() { -io.sourceFromRuntimePath(['libly.js']); if (!liberator.plugins.libly) { - liberator.log('notifier: needs libly.js'); + liberator.log('notifier: needs _libly.js'); return; } @@ -37,11 +127,10 @@ function bootstrap() { this.initialize.apply(this, arguments); }; Loader.prototype = { - initialize: function(name, registerHook) { + initialize: function(name) { liberator.plugins.notifier[name] = this; this.name = name; this.plugins = []; - this.registerHook = registerHook; this.load(name); }, load: function(name) { @@ -56,8 +145,8 @@ function bootstrap() { }); }); }, - register: function(plugin) { - this.plugins.push(this.registerHook(plugin)); + register: function(baseClass, pluginExtends) { + this.plugins.push(new baseClass(pluginExtends)); }, unregister: function(plugin) { var ret = []; @@ -105,8 +194,7 @@ function bootstrap() { __initialize__: function(args) { this.isActive = false; this.observers = []; - this.interval = 0; - //if (this.interval < 60) this.interval = 60; + this.interval = 60; this.__nextTime = new Date(); $U.extend(this, args); if (typeof this.initialize == 'function') this.initialize(); @@ -128,6 +216,50 @@ function bootstrap() { check: function() { throw 'needs override.' } };//}}} + var SubjectHttp = Subject;//{{{ + $U.extend(SubjectHttp.prototype, { + initialize: function() { + this.initialized = false; + this.count = 0; + this.cache; + + var req = new libly.Request( + this.options.url, + this.options.headers, + this.options.extra + ); + req.addEventListener('onSuccess', $U.bind(this, function(res) { + if (typeof this.parse == 'function') this.cache = this.parse(res); + if (this.cache) + this.initialized = true; + })); + req.get(); + }, + check: function() { + if (!this.initialized) return; + + this.count++; + var req = new libly.Request( + this.options.url, + this.options.headers, + this.options.extra + ); + req.addEventListener('onSuccess', $U.bind(this, function(res) { + var parsed, diff; + if (typeof this.parse == 'function') parsed = this.parse(res); + if (parsed && typeof this.diff == 'function') diff = this.diff(this.cache, parsed); + if (diff && (typeof diff.length != 'undefined' && diff.length > 0)) { + if (typeof this.buildMessages == 'function') { + let messages = this.buildMessages([].concat(diff)); + [].concat(messages).forEach($U.bind(this, function(m) this.notify(m))); + } + this.cache = parsed; + } + })); + req.get(); + } + });//}}} + var Notifier = function() {//{{{ this.initialize.apply(this, arguments); }; @@ -143,7 +275,7 @@ function bootstrap() { setup: function() {//{{{ if (this.isBusy) { - logger.log('bussy.' + this.id); + logger.log('busy.' + this.id); return; } @@ -161,6 +293,9 @@ function bootstrap() { ); liberator.plugins.notifier.libly = libly; + liberator.plugins.notifier.Observer = Observer; + liberator.plugins.notifier.Subject = Subject; + liberator.plugins.notifier.SubjectHttp = SubjectHttp; liberator.plugins.notifier.Message = Message; this.observers = new Loader('observer', function(args) new Observer(args)); @@ -204,7 +339,7 @@ function bootstrap() { s.isActive = false; s.__nextTime = new Date(s.__nextTime.getTime() + s.interval * 1000); if (s.__nextTime < now) s.__nextTime = now; - }, 10); + }, 1000); } }); liberator.sleep(3 * 1000); -- cgit v1.2.3