diff --git a/component.json b/component.json index a9e969e..1bf5e3d 100644 --- a/component.json +++ b/component.json @@ -1,6 +1,6 @@ { "name": "postal.js", - "version": "0.7.3", + "version": "0.8.0", "main": ["lib/standard/postal.min.js", "lib/standard/postal.js"], "dependencies": { "underscore": "~1.3.0" diff --git a/example/amd/js/examples.js b/example/amd/js/examples.js index 8e9fc13..c7291cb 100644 --- a/example/amd/js/examples.js +++ b/example/amd/js/examples.js @@ -1,13 +1,13 @@ define( ['postal', 'postaldiags'], function ( postal, diags ) { - // The world's simplest subscription - var channel = postal.channel( "Name.Changed" ); + // This gets you a handle to the default postal channel... + var channel = postal.channel(); // subscribe - var subscription = channel.subscribe( function ( data ) { + var subscription = channel.subscribe( "Name.Changed", function ( data ) { $( "#example1" ).html( "Name: " + data.name ); } ); // And someone publishes a first name change: - channel.publish( { name : "Dr. Who" } ); + channel.publish( "Name.Changed", { name : "Dr. Who" } ); subscription.unsubscribe(); @@ -15,14 +15,11 @@ define( ['postal', 'postaldiags'], function ( postal, diags ) { // The # symbol represents "one word" in a topic (i.e - the text between two periods of a topic). // By subscribing to "#.Changed", the binding will match // Name.Changed & Location.Changed but *not* for Changed.Companion - var hashChannel = postal.channel( "#.Changed" ), - chgSubscription = hashChannel.subscribe( function ( data ) { - $( '
  • ' + data.type + " Changed: " + data.value + '
  • ' ).appendTo( "#example2" ); - } ); - postal.channel( "Name.Changed" ) - .publish( { type : "Name", value : "John Smith" } ); - postal.channel( "Location.Changed" ) - .publish( { type : "Location", value : "Early 20th Century England" } ); + var chgSubscription = channel.subscribe( "#.Changed", function ( data ) { + $( '
  • ' + data.type + " Changed: " + data.value + '
  • ' ).appendTo( "#example2" ); + } ); + channel.publish( "Name.Changed", { type : "Name", value : "John Smith" } ); + channel.publish( "Location.Changed", { type : "Location", value : "Early 20th Century England" } ); chgSubscription.unsubscribe(); @@ -30,120 +27,85 @@ define( ['postal', 'postaldiags'], function ( postal, diags ) { // The * symbol represents any number of characters/words in a topic string. // By subscribing to "DrWho.*.Changed", the binding will match // DrWho.NinthDoctor.Companion.Changed & DrWho.Location.Changed but *not* Changed - var starChannel = postal.channel( "DrWho.*.Changed" ), - starSubscription = starChannel.subscribe( function ( data ) { - $( '
  • ' + data.type + " Changed: " + data.value + '
  • ' ).appendTo( "#example3" ); - } ); - postal.channel( "DrWho.NinthDoctor.Companion.Changed" ) - .publish( { type : "Companion Name", value : "Rose" } ); - postal.channel( "DrWho.TenthDoctor.Companion.Changed" ) - .publish( { type : "Companion Name", value : "Martha" } ); - postal.channel( "DrWho.Eleventh.Companion.Changed" ) - .publish( { type : "Companion Name", value : "Amy" } ); - postal.channel( "DrWho.Location.Changed" ) - .publish( { type : "Location", value : "The Library" } ); - postal.channel( "TheMaster.DrumBeat.Changed" ) - .publish( { type : "DrumBeat", value : "This won't trigger any subscriptions" } ); - postal.channel( "Changed" ) - .publish( { type : "Useless", value : "This won't trigger any subscriptions either" } ); + var starSubscription = channel.subscribe( "DrWho.*.Changed", function ( data ) { + $( '
  • ' + data.type + " Changed: " + data.value + '
  • ' ).appendTo( "#example3" ); + } ); + channel.publish( "DrWho.NinthDoctor.Companion.Changed", { type : "Companion Name", value : "Rose" } ); + channel.publish( "DrWho.TenthDoctor.Companion.Changed", { type : "Companion Name", value : "Martha" } ); + channel.publish( "DrWho.Eleventh.Companion.Changed", { type : "Companion Name", value : "Amy" } ); + channel.publish( "DrWho.Location.Changed", { type : "Location", value : "The Library" } ); + channel.publish( "TheMaster.DrumBeat.Changed", { type : "DrumBeat", value : "This won't trigger any subscriptions" } ); + channel.publish( "Changed", { type : "Useless", value : "This won't trigger any subscriptions either" } ); starSubscription.unsubscribe(); // Applying distinctUntilChanged to a subscription - var dupChannel = postal.channel( "WeepingAngel.*" ), - dupSubscription = dupChannel.subscribe( - function ( data ) { - $( '
  • ' + data.value + '
  • ' ).appendTo( "#example4" ); - } ).distinctUntilChanged(); - postal.channel( "WeepingAngel.DontBlink" ) - .publish( { value : "Don't Blink" } ); - postal.channel( "WeepingAngel.DontBlink" ) - .publish( { value : "Don't Blink" } ); - postal.channel( "WeepingAngel.DontEvenBlink" ) - .publish( { value : "Don't Even Blink" } ); - postal.channel( "WeepingAngel.DontBlink" ) - .publish( { value : "Don't Close Your Eyes" } ); - postal.channel( "WeepingAngel.DontBlink" ) - .publish( { value : "Don't Blink" } ); - postal.channel( "WeepingAngel.DontBlink" ) - .publish( { value : "Don't Blink" } ); + var dupSubscription = channel.subscribe( "WeepingAngel.*", + function ( data ) { + $( '
  • ' + data.value + '
  • ' ).appendTo( "#example4" ); + } ).distinctUntilChanged(); + channel.publish( "WeepingAngel.DontBlink", { value : "Don't Blink" } ); + channel.publish( "WeepingAngel.DontBlink", { value : "Don't Blink" } ); + channel.publish( "WeepingAngel.DontEvenBlink", { value : "Don't Even Blink" } ); + channel.publish( "WeepingAngel.DontBlink", { value : "Don't Close Your Eyes" } ); + channel.publish( "WeepingAngel.DontBlink", { value : "Don't Blink" } ); + channel.publish( "WeepingAngel.DontBlink", { value : "Don't Blink" } ); dupSubscription.unsubscribe(); // Using disposeAfter(X) to remove subscription automagically after X number of receives - var daChannel = postal.channel( "Donna.Noble.*" ), - daSubscription = daChannel.subscribe( - function ( data ) { - $( '
  • ' + data.value + '
  • ' ).appendTo( "#example5" ); - } ).disposeAfter( 2 ); - postal.channel( "Donna.Noble.ScreamingAgain" ) - .publish( { value : "Donna Noble has left the library." } ); - postal.channel( "Donna.Noble.ScreamingAgain" ) - .publish( { value : "Donna Noble has left the library." } ); - postal.channel( "Donna.Noble.ScreamingAgain" ) - .publish( { value : "Donna Noble has left the library." } ); - postal.channel( "Donna.Noble.ScreamingAgain" ) - .publish( { value : "Donna Noble has left the library." } ); - postal.channel( "Donna.Noble.ScreamingAgain" ) - .publish( { value : "Donna Noble has left the library." } ); + var daSubscription = channel.subscribe( "Donna.Noble.*", + function ( data ) { + $( '
  • ' + data.value + '
  • ' ).appendTo( "#example5" ); + } ).disposeAfter( 2 ); + channel.publish( "Donna.Noble.ScreamingAgain", { value : "Donna Noble has left the library." } ); + channel.publish( "Donna.Noble.ScreamingAgain", { value : "Donna Noble has left the library." } ); + channel.publish( "Donna.Noble.ScreamingAgain", { value : "Donna Noble has left the library." } ); + channel.publish( "Donna.Noble.ScreamingAgain", { value : "Donna Noble has left the library." } ); + channel.publish( "Donna.Noble.ScreamingAgain", { value : "Donna Noble has left the library." } ); daSubscription.unsubscribe(); // Using withConstraint to apply a predicate to the subscription var drIsInTheTardis = false, - wcChannel = postal.channel( "Tardis.Depart" ), - wcSubscription = wcChannel.subscribe( + wcSubscription = channel.subscribe( "Tardis.Depart", function ( data ) { $( '
  • ' + data.value + '
  • ' ).appendTo( "#example6" ); } ).withConstraint( function () { return drIsInTheTardis; } ); - postal.channel( "Tardis.Depart" ) - .publish( { value : "Time for time travel....fantastic!" } ); - postal.channel( "Tardis.Depart" ) - .publish( { value : "Time for time travel....fantastic!" } ); + channel.publish( "Tardis.Depart", { value : "Time for time travel....fantastic!" } ); + channel.publish( "Tardis.Depart", { value : "Time for time travel....fantastic!" } ); drIsInTheTardis = true; - postal.channel( "Tardis.Depart" ) - .publish( { value : "Time for time travel....fantastic!" } ); + channel.publish( "Tardis.Depart", { value : "Time for time travel....fantastic!" } ); wcSubscription.unsubscribe(); // Using withContext to set the "this" context - var ctxChannel = postal.channel( "Dalek.Meet.CyberMen" ), - ctxSubscription = ctxChannel.subscribe( - function ( data ) { - $( '
  • ' + data.value + '
  • ' ).appendTo( this ); - } ).withContext( $( "#example7" ) ); - postal.channel( "Dalek.Meet.CyberMen" ) - .publish( { value : "Exterminate!" } ); - postal.channel( "Dalek.Meet.CyberMen" ) - .publish( { value : "Delete!" } ); + var ctxSubscription = channel.subscribe( "Dalek.Meet.CyberMen", + function ( data ) { + $( '
  • ' + data.value + '
  • ' ).appendTo( this ); + } ).withContext( $( "#example7" ) ); + channel.publish( "Dalek.Meet.CyberMen", { value : "Exterminate!" } ); + channel.publish( "Dalek.Meet.CyberMen", { value : "Delete!" } ); ctxSubscription.unsubscribe(); // Using withDelay() to delay the subscription evaluation - var wdChannel = postal.channel( "He.Will.Knock.Four.Times" ), - wdSubscription = wdChannel.subscribe( - function ( data ) { - $( '
  • ' + data.value + '
  • ' ).appendTo( $( "#example8" ) ); - } ).withDelay( 5000 ); - postal.channel( "He.Will.Knock.Four.Times" ) - .publish( { value : "Knock!" } ); - postal.channel( "He.Will.Knock.Four.Times" ) - .publish( { value : "Knock!" } ); - postal.channel( "He.Will.Knock.Four.Times" ) - .publish( { value : "Knock!" } ); - postal.channel( "He.Will.Knock.Four.Times" ) - .publish( { value : "Knock!" } ); + var wdSubscription = channel.subscribe( "He.Will.Knock.Four.Times", + function ( data ) { + $( '
  • ' + data.value + '
  • ' ).appendTo( $( "#example8" ) ); + } ).withDelay( 5000 ); + channel.publish( "He.Will.Knock.Four.Times", { value : "Knock!" } ); + channel.publish( "He.Will.Knock.Four.Times", { value : "Knock!" } ); + channel.publish( "He.Will.Knock.Four.Times", { value : "Knock!" } ); + channel.publish( "He.Will.Knock.Four.Times", { value : "Knock!" } ); wdSubscription.unsubscribe(); // Using distinct() to ignore duplicate messages - var revealChannel = postal.channel('detect.cylon'), - revealSubscription = revealChannel.subscribe(function (who) { - $('
  • ').text(who.name).appendTo($('#example9')); - }).distinct(); - postal.channel('detect.cylon').publish({name: 'Boomer'}); - postal.channel('detect.cylon').publish({name: 'Saul Tigh'}); - postal.channel('detect.cylon').publish({name: 'William Adama'}); - postal.channel('detect.cylon').publish({name: 'Helo'}); - //ignored! - postal.channel('detect.cylon').publish({name: 'Boomer'}); - postal.channel('detect.cylon').publish({name: 'Felix Gaeta'}); - //ignored! - postal.channel('detect.cylon').publish({name: 'William Adama'}); + var revealSubscription = channel.subscribe( 'detect.cylon',function ( who ) { + $( '
  • ' ).text( who.name ).appendTo( $( '#example9' ) ); + } ).distinct(); + channel.publish( 'detect.cylon', {name : 'Boomer'} ); + channel.publish( 'detect.cylon', {name : 'Saul Tigh'} ); + channel.publish( 'detect.cylon', {name : 'William Adama'} ); + channel.publish( 'detect.cylon', {name : 'Helo'} ); + channel.publish( 'detect.cylon', {name : 'Boomer'} ); //ignored! + channel.publish( 'detect.cylon', {name : 'Felix Gaeta'} ); + channel.publish( 'detect.cylon', {name : 'William Adama'} );//ignored! } ); \ No newline at end of file diff --git a/example/amd/js/libs/postal/postal.js b/example/amd/js/libs/postal/postal.js index 82deed7..84c2659 100644 --- a/example/amd/js/libs/postal/postal.js +++ b/example/amd/js/libs/postal/postal.js @@ -54,44 +54,22 @@ return isDistinct; }; }; - var ChannelDefinition = function ( channelName, defaultTopic ) { + var ChannelDefinition = function ( channelName ) { this.channel = channelName || DEFAULT_CHANNEL; - this._topic = defaultTopic || ""; }; ChannelDefinition.prototype = { subscribe : function () { - var len = arguments.length; - if ( len === 1 ) { - return new SubscriptionDefinition( this.channel, this._topic, arguments[0] ); - } - else if ( len === 2 ) { - return new SubscriptionDefinition( this.channel, arguments[0], arguments[1] ); - } + return arguments.length === 1 ? + new SubscriptionDefinition( this.channel, arguments[0].topic, arguments[0].callback ) : + new SubscriptionDefinition( this.channel, arguments[0], arguments[1] ); }, - publish : function ( obj ) { - var _obj = obj || {}; - var envelope = { - channel : this.channel, - topic : this._topic, - data : _obj - }; - // If this is an envelope.... - if ( _obj.topic && _obj.data ) { - envelope = _obj; - envelope.channel = envelope.channel || this.channel; - } - envelope.timeStamp = new Date(); + publish : function () { + var envelope = arguments.length === 1 ? arguments[0] : { topic: arguments[0], data: arguments[1] }; + envelope.channel = this.channel; postal.configuration.bus.publish( envelope ); return envelope; - }, - - topic : function ( topic ) { - if ( topic === this._topic ) { - return this; - } - return new ChannelDefinition( this.channel, topic ); } }; @@ -302,6 +280,7 @@ }, publish : function ( envelope ) { + envelope.timeStamp = new Date(); _.each( this.wireTaps, function ( tap ) { tap( envelope.data, envelope ); } ); @@ -371,55 +350,7 @@ } }; - var publishPicker = { - "1" : function ( envelope ) { - if ( !envelope ) { - throw new Error( "publishing from the 'global' postal.publish call requires a valid envelope." ); - } - envelope.channel = envelope.channel || DEFAULT_CHANNEL; - envelope.timeStamp = new Date(); - postal.configuration.bus.publish( envelope ); - return envelope; - }, - "2" : function ( topic, data ) { - var envelope = { channel : DEFAULT_CHANNEL, topic : topic, timeStamp : new Date(), data : data }; - postal.configuration.bus.publish( envelope ); - return envelope; - }, - "3" : function ( channel, topic, data ) { - var envelope = { channel : channel, topic : topic, timeStamp : new Date(), data : data }; - postal.configuration.bus.publish( envelope ); - return envelope; - } - }, - channelPicker = { - "1" : function ( chn ) { - var channel = chn, topic, options = {}; - if ( Object.prototype.toString.call( channel ) === "[object String]" ) { - channel = DEFAULT_CHANNEL; - topic = chn; - } - else { - channel = chn.channel || DEFAULT_CHANNEL; - topic = chn.topic; - options = chn.options || options; - } - return new postal.channelTypes[ options.type || "local" ]( channel, topic ); - }, - "2" : function ( chn, tpc ) { - var channel = chn, topic = tpc, options = {}; - if ( Object.prototype.toString.call( tpc ) === "[object Object]" ) { - channel = DEFAULT_CHANNEL; - topic = chn; - options = tpc; - } - return new postal.channelTypes[ options.type || "local" ]( channel, topic ); - }, - "3" : function ( channel, topic, options ) { - return new postal.channelTypes[ options.type || "local" ]( channel, topic ); - } - }, - sessionInfo = {}; + var sessionInfo = {}; // save some setup time, albeit tiny localBus.subscriptions[SYSTEM_CHANNEL] = {}; @@ -434,29 +365,22 @@ SYSTEM_CHANNEL : SYSTEM_CHANNEL }, - channelTypes : { - local : ChannelDefinition - }, + ChannelDefinition : ChannelDefinition, - channel : function () { - var len = arguments.length; - if ( channelPicker[len] ) { - return channelPicker[len].apply( this, arguments ); - } + SubscriptionDefinition: SubscriptionDefinition, + + channel : function ( channelName ) { + return new ChannelDefinition( channelName ); }, subscribe : function ( options ) { - var callback = options.callback, - topic = options.topic, - channel = options.channel || DEFAULT_CHANNEL; - return new SubscriptionDefinition( channel, topic, callback ); + return new SubscriptionDefinition( options.channel || DEFAULT_CHANNEL, options.topic, options.callback ); }, - publish : function () { - var len = arguments.length; - if ( publishPicker[len] ) { - return publishPicker[len].apply( this, arguments ); - } + publish : function ( envelope ) { + envelope.channel = envelope.channel || DEFAULT_CHANNEL; + postal.configuration.bus.publish( envelope ); + return envelope; }, addWireTap : function ( callback ) { diff --git a/example/amd/js/libs/postal/postal.min.js b/example/amd/js/libs/postal/postal.min.js index 33f3940..d54f028 100644 --- a/example/amd/js/libs/postal/postal.min.js +++ b/example/amd/js/libs/postal/postal.min.js @@ -4,4 +4,4 @@ License: Dual licensed MIT (http://www.opensource.org/licenses/mit-license) & GPL (http://www.opensource.org/licenses/gpl-license) Version 0.7.3 */ -(function(e,t){typeof define=="function"&&define.amd?define(["underscore"],function(n){return t(n,e)}):t(e._,e)})(this,function(e,t,n){var r="/",i=50,s=0,o="postal",u=function(){},a=function(){var t;return function(n){var r=!1;return e.isString(n)?(r=n===t,t=n):(r=e.isEqual(n,t),t=e.clone(n)),!r}},f=function(){var t=[];return function(n){var r=!e.any(t,function(t){return e.isObject(n)||e.isArray(n)?e.isEqual(n,t):n===t});return r&&t.push(n),r}},l=function(e,t){this.channel=e||r,this._topic=t||""};l.prototype={subscribe:function(){var e=arguments.length;if(e===1)return new c(this.channel,this._topic,arguments[0]);if(e===2)return new c(this.channel,arguments[0],arguments[1])},publish:function(e){var t=e||{},n={channel:this.channel,topic:this._topic,data:t};return t.topic&&t.data&&(n=t,n.channel=n.channel||this.channel),n.timeStamp=new Date,g.configuration.bus.publish(n),n},topic:function(e){return e===this._topic?this:new l(this.channel,e)}};var c=function(e,t,n){this.channel=e,this.topic=t,this.callback=n,this.priority=i,this.constraints=new Array(0),this.maxCalls=s,this.onHandled=u,this.context=null,g.configuration.bus.publish({channel:o,topic:"subscription.created",timeStamp:new Date,data:{event:"subscription.created",channel:e,topic:t}}),g.configuration.bus.subscribe(this)};c.prototype={unsubscribe:function(){g.configuration.bus.unsubscribe(this),g.configuration.bus.publish({channel:o,topic:"subscription.removed",timeStamp:new Date,data:{event:"subscription.removed",channel:this.channel,topic:this.topic}})},defer:function(){var e=this.callback;return this.callback=function(t){setTimeout(e,0,t)},this},disposeAfter:function(t){if(e.isNaN(t)||t<=0)throw"The value provided to disposeAfter (maxCalls) must be a number greater than zero.";var n=this.onHandled,r=e.after(t,e.bind(function(){this.unsubscribe(this)},this));return this.onHandled=function(){n.apply(this.context,arguments),r()},this},distinctUntilChanged:function(){return this.withConstraint(new a),this},distinct:function(){return this.withConstraint(new f),this},once:function(){this.disposeAfter(1)},withConstraint:function(t){if(!e.isFunction(t))throw"Predicate constraint must be a function";return this.constraints.push(t),this},withConstraints:function(t){var n=this;return e.isArray(t)&&e.each(t,function(e){n.withConstraint(e)}),n},withContext:function(e){return this.context=e,this},withDebounce:function(t){if(e.isNaN(t))throw"Milliseconds must be a number";var n=this.callback;return this.callback=e.debounce(n,t),this},withDelay:function(t){if(e.isNaN(t))throw"Milliseconds must be a number";var n=this.callback;return this.callback=function(e){setTimeout(function(){n(e)},t)},this},withPriority:function(t){if(e.isNaN(t))throw"Priority must be a number";return this.priority=t,g.configuration.bus.changePriority(this),this},withThrottle:function(t){if(e.isNaN(t))throw"Milliseconds must be a number";var n=this.callback;return this.callback=e.throttle(n,t),this},subscribe:function(e){return this.callback=e,this}};var h={cache:{},compare:function(e,t){if(this.cache[t]&&this.cache[t][e])return!0;var n=("^"+e.replace(/\./g,"\\.").replace(/\*/g,"[A-Z,a-z,0-9]*").replace(/#/g,".*")+"$").replace("\\..*$","(\\..*)*$").replace("^.*\\.","^(.*\\.)*"),r=new RegExp(n),i=r.test(t);return i&&(this.cache[t]||(this.cache[t]={}),this.cache[t][e]=!0),i},reset:function(){this.cache={}}},p={addWireTap:function(e){var t=this;return t.wireTaps.push(e),function(){var n=t.wireTaps.indexOf(e);n!==-1&&t.wireTaps.splice(n,1)}},changePriority:function(t){var n,r;if(this.subscriptions[t.channel]&&this.subscriptions[t.channel][t.topic]){this.subscriptions[t.channel][t.topic]=e.without(this.subscriptions[t.channel][t.topic],t),n=this.subscriptions[t.channel][t.topic].length-1;for(;n>=0;n--)if(this.subscriptions[t.channel][t.topic][n].priority<=t.priority){this.subscriptions[t.channel][t.topic].splice(n+1,0,t),r=!0;break}r||this.subscriptions[t.channel][t.topic].unshift(t)}},publish:function(t){e.each(this.wireTaps,function(e){e(t.data,t)}),this.subscriptions[t.channel]&&e.each(this.subscriptions[t.channel],function(n){e.each(e.clone(n),function(n){g.configuration.resolver.compare(n.topic,t.topic)&&e.all(n.constraints,function(e){return e.call(n.context,t.data,t)})&&typeof n.callback=="function"&&(n.callback.call(n.context,t.data,t),n.onHandled())})})},reset:function(){this.subscriptions&&(e.each(this.subscriptions,function(t){e.each(t,function(e){while(e.length)e.pop().unsubscribe()})}),this.subscriptions={})},subscribe:function(e){var t,n,r,i=this.subscriptions[e.channel],s;return i||(i=this.subscriptions[e.channel]={}),s=this.subscriptions[e.channel][e.topic],s||(s=this.subscriptions[e.channel][e.topic]=new Array(0)),s.push(e),e},subscriptions:{},wireTaps:new Array(0),unsubscribe:function(e){if(this.subscriptions[e.channel][e.topic]){var t=this.subscriptions[e.channel][e.topic].length,n=0;for(;n=0;n--)if(this.subscriptions[t.channel][t.topic][n].priority<=t.priority){this.subscriptions[t.channel][t.topic].splice(n+1,0,t),r=!0;break}r||this.subscriptions[t.channel][t.topic].unshift(t)}},publish:function(t){t.timeStamp=new Date,e.each(this.wireTaps,function(e){e(t.data,t)}),this.subscriptions[t.channel]&&e.each(this.subscriptions[t.channel],function(n){e.each(e.clone(n),function(n){v.configuration.resolver.compare(n.topic,t.topic)&&e.all(n.constraints,function(e){return e.call(n.context,t.data,t)})&&typeof n.callback=="function"&&(n.callback.call(n.context,t.data,t),n.onHandled())})})},reset:function(){this.subscriptions&&(e.each(this.subscriptions,function(t){e.each(t,function(e){while(e.length)e.pop().unsubscribe()})}),this.subscriptions={})},subscribe:function(e){var t,n,r,i=this.subscriptions[e.channel],s;return i||(i=this.subscriptions[e.channel]={}),s=this.subscriptions[e.channel][e.topic],s||(s=this.subscriptions[e.channel][e.topic]=new Array(0)),s.push(e),e},subscriptions:{},wireTaps:new Array(0),unsubscribe:function(e){if(this.subscriptions[e.channel][e.topic]){var t=this.subscriptions[e.channel][e.topic].length,n=0;for(;n - - - - Twitter Hash Tag Stats Demo - - - - - - - - \ No newline at end of file diff --git a/example/node/client/js/infrastructure/app.js b/example/node/client/js/infrastructure/app.js deleted file mode 100644 index 6bc83fa..0000000 --- a/example/node/client/js/infrastructure/app.js +++ /dev/null @@ -1,55 +0,0 @@ -define( [ - 'jquery', - 'backbone', - 'bus', - 'infrastructure/router', - 'infrastructure/view-manager', - 'views/container', - 'views/menu', - 'views/tweet-count', - 'views/mention-count', - 'views/mentioner-count', - 'views/hash-tag-count', - 'views/profanity-percentage', - 'views/search-requests', - 'views/wiretap', -], function ( $, Backbone, bus, Router, ViewManager, ContainerView, MenuView, TweetCountView, - MentionCountView, MentionerCountView, HashTagCountView, ProfanityPercentage, - SearchRequestView, WiretapView ) { - var app = { - bus : bus, - router : new Router() - }; - - // Set up UI concerns - app.viewManager = new ViewManager(); - app.bus.viewManager.subscribe( "ui.show", function ( data, env ) { - app.viewManager.UI[ data.name ].activate( data.context ); - } ); - - app.viewManager.registerViews( [ - { name : "container", ctor : ContainerView }, - { name : "menu", ctor : MenuView }, - { name : "tweetCount", ctor : TweetCountView }, - { name : "mentionCount", ctor : MentionCountView }, - { name : "mentionerCount", ctor : MentionerCountView }, - { name : "hashTagCount", ctor : HashTagCountView }, - { name : "profanityPercentage", ctor : ProfanityPercentage }, - { name : "searchRequests", ctor : SearchRequestView }, - { name : "wiretap", ctor : WiretapView } - ] ); - app.viewManager.defineUIs( [ - { name : "homeUI", dependencies : [ "container", "menu", "tweetCount", "mentionCount", "mentionerCount", "hashTagCount", "profanityPercentage" ] }, - { name : "searchRequestUI", dependencies : [ "container", "menu", "searchRequests" ] }, - { name : "wireTapLogUI", dependencies : [ "container", "menu", "wiretap" ] } - ] ); - - $( function () { - Backbone.history.start( { - pushState : true, - root : $( "base" ).attr( "href" ) - } ); - } ); - - return app; -} ); \ No newline at end of file diff --git a/example/node/client/js/infrastructure/bus.js b/example/node/client/js/infrastructure/bus.js deleted file mode 100644 index afb50a7..0000000 --- a/example/node/client/js/infrastructure/bus.js +++ /dev/null @@ -1,11 +0,0 @@ -define( [ - 'postal' -], function ( postal ) { - return { - router : postal.channel( "router", "*" ), - viewManager : postal.channel( "viewmanager", "*" ), - data : postal.channel( "data", "*" ), - app : postal.channel( "statsApp", "*", { type : "websocket" } ), - stats : postal.channel( "stats", "*", { type : "websocket" } ) - } -} ); \ No newline at end of file diff --git a/example/node/client/js/infrastructure/postal.socket-client.js b/example/node/client/js/infrastructure/postal.socket-client.js deleted file mode 100644 index 2a56270..0000000 --- a/example/node/client/js/infrastructure/postal.socket-client.js +++ /dev/null @@ -1,298 +0,0 @@ -/* - postal.socket - Author: Jim Cowart - License: Dual licensed MIT (http://www.opensource.org/licenses/mit-license) & GPL (http://www.opensource.org/licenses/gpl-license) - Version 0.1.0 - */ - -(function ( root, doc, factory ) { - if ( typeof define === "function" && define.amd ) { - // AMD. Register as an anonymous module. - define( [ "underscore", "machina", "postal" ], function ( _, machina, postal ) { - return factory( _, machina, postal, root, doc ); - } ); - } else { - // Browser globals - factory( root._, root.machina, root.postal, root, doc ); - } -}( this, document, function ( _, machina, postal, global, document, undefined ) { - - /* - adding a socket namespace to postal - which provides the following members: - 1.) config - provides values used to manage the socket connection - 2.) goOffline() - tells the manager to close the connection intentionally - 3.) goOnline() - tells the manager to try to connect. - 4.) manifest - an array of objects describing the subscriptions that have been - set up on the remote end. - 5.) publish() - takes a valid postal envelope and pushes it through the socket - to be published to the server instance of postal. - 6.) socketMgr - the FSM managing the socket connection - 7.) socketNamespace - exposed currently for debugging only - 8.) subscribe() - passes an object through the socket to the server - which contains data necessary to set up a remote subscription. The - options passed to the socket would look similar to this: - { - "channel":"SomeChannel", - "topic":"my.topic", - "correlationId":"2073383865318591267" - } - The "correlationId" is used on the remote side to apply a constraint to - the subscription, enabling just this specific client to be targeted on - and otherwise public channel. - 9.) unsubscribe() - passes an object through the socket to the server - which contains data necessary to remove a remote subscription. The options - passed would look similar to the example above in #8. - */ - postal.connections = postal.connections || {}; - - var postalSocket = postal.connections.socket = (function () { - var socketNamespace, - fsm = new machina.Fsm( { - retryFn : undefined, - - session : undefined, - - wireUpSocketEvents : function () { - var self = this; - _.each( [ "connect", "connecting", "connect_failed", "disconnect", "reconnect", "reconnect_failed", - "reconnecting", "postal.socket.remote", "postal.socket.identified", "postal.socket.migration" ], - function ( evnt ) { - socketNamespace.on( evnt, function ( data ) { - self.handle( evnt, data ); - } ); - } ); - }, - - states : { - uninitialized : { - tryConnect : function () { - this.transition( "initializing" ); - } - }, - initializing : { - _onEnter : function () { - socketNamespace = io.connect( postalSocket.config.url, { "auto connect" : false } ); - this.wireUpSocketEvents(); - this.transition( "probing" ) - }, - socketTransmit : function () { - this.deferUntilTransition( "online" ); - } - }, - probing : { - _onEnter : function () { - clearTimeout( this.retryFn ); - if ( !socketNamespace.socket.connecting && !socketNamespace.socket.reconnecting ) { - socketNamespace.socket.connect(); - } - else { - this.transition( "settingSessionInfo" ); - } - }, - connect : function () { - this.transition( "settingSessionInfo" ); - }, - connect_failed : function () { - this.transition( "disconnected" ); - }, - maxAttempts : function () { - this.transition( "offline" ); - }, - "postal.socket.remote" : function () { - this.deferUntilTransition( "online" ); - }, - reconnect : function () { - this.transition( "settingSessionInfo" ); - }, - reconnect_failed : function () { - this.transition( "disconnected" ); - }, - socketTransmit : function () { - this.deferUntilTransition( "online" ); - } - }, - settingSessionInfo : { - _onEnter : function () { - var self = this; - postal.utils.setSessionId( socketNamespace.socket.sessionid, function ( session ) { - self.session = session; - self.transition( "identifying" ); - } ); - } - }, - identifying : { - _onEnter : function () { - var self = this; - self.retryFn = setTimeout( function () { - self.handle( "timeout.identifying" ); - }, postalSocket.config.reconnectInterval ); - self.handle( "client.identifier" ); - }, - "client.identifier" : function () { - clearTimeout( this.retryFn ); - socketNamespace.emit( "postal.clientId", { id : this.session.id, lastId : this.session.lastId } ); - }, - connect_failed : function () { - this.transition( "disconnected" ); - }, - disconnect : function () { - this.transition( "probing" ); - }, - "postal.socket.identified" : function ( data ) { - this.transition( "online" ); - }, - "postal.socket.migration" : function () { - _.each( postal.connections.socket.manifest, function ( sub ) { - fsm.handle( "socketTransmit", "postal.subscribe", sub ); - } ); - socketNamespace.emit( "postal.migrationComplete", {} ); - }, - "postal.socket.remote" : function () { - this.deferUntilTransition( "online" ); - }, - reconnect_failed : function () { - this.transition( "disconnected" ); - }, - socketTransmit : function ( evntName, envelope ) { - if ( evntName === "postal.subscribe" ) { - // we risk mutating the message here, so extend - // and add the correlationId to the extended copy - var socketEnv = _.extend( {}, envelope ); - socketEnv.correlationId = this.session.id; - socketNamespace.emit( evntName, socketEnv ); - } - else { - this.deferUntilTransition( "online" ); - } - }, - "timeout.identifying" : function () { - this.transition( "probing" ); - } - }, - online : { - disconnect : function () { - this.transition( "probing" ); - }, - goOffline : function () { - this.transition( "offline" ); - }, - "postal.socket.remote" : function ( envelope ) { - postal.publish( envelope ); - }, - socketTransmit : function ( evntName, envelope ) { - // we risk mutating the message here, so extend - // and add the correlationId to the extended copy - var socketEnv = _.extend( {}, envelope ); - socketEnv.correlationId = this.session.id; - socketNamespace.emit( evntName, socketEnv ); - } - }, - offline : { - _onEnter : function () { - socketNamespace.socket.disconnect(); - }, - socketTransmit : function () { - this.deferUntilTransition( "online" ); - }, - "tryConnect" : function () { - this.transition( "probing" ); - } - }, - disconnected : { - _onEnter : function () { - var self = this; - self.retryFn = setTimeout( function () { - self.transition( "probing" ); - }, postalSocket.config.reconnectInterval ); - }, - connecting : function () { - this.transition( "probing" ); - }, - reconnecting : function () { - this.transition( "probing" ); - }, - socketTransmit : function () { - this.deferUntilTransition( "online" ); - } - } - } - } ); - postal.subscribe( { - channel : "postal", - topic : "sessionId.changed", - callback : function () { - fsm.handle( "postal.session.changed" ); - } - } ); - return { - config : { - url : window.location.origin, - reconnectInterval : 4000 - }, - goOffline : function () { - fsm.handle( "goOffline" ); - }, - goOnline : function () { - fsm.handle( "tryConnect" ); - }, - manifest : [], - publish : function ( envelope ) { - fsm.handle( "socketTransmit", "postal.publish", envelope ); - }, - subscribe : function ( options ) { - options.channel = options.channel || postal.configuration.DEFAULT_CHANNEL; - options.topic = options.topic || "*"; - if ( !_.any( this.manifest, function ( item ) { - return item.channel === options.channel && item.topic === options.topic; - } ) ) { - this.manifest.push( options ); - fsm.handle( "socketTransmit", "postal.subscribe", options ); - } - }, - socketMgr : fsm, - socketNamespace : socketNamespace, - unsubscribe : function ( options ) { - options.channel = options.channel || postal.configuration.DEFAULT_CHANNEL; - options.topic = options.topic || "*"; - if ( !postal.getSubscribersFor( options.channel, options.topic ).length ) { - fsm.handle( "socketTransmit", "postal.unsubscribe", options ); - } - } - } - })(); - - postal.connections.socket.goOnline(); - var SocketChannel = postal.channelTypes.websocket = function ( channelName, defaultTopic ) { - var channel = postal.channel( channelName, defaultTopic ), - localSubscribe = channel.subscribe, - localPublish = channel.publish, - localTopic = channel.topic; - - channel.publish = function () { - postalSocket.publish( localPublish.apply( channel, arguments ) ); - }; - - channel.subscribe = function () { - var sub = localSubscribe.apply( channel, arguments ), - origUnsubscribe; - origUnsubscribe = sub.unsubscribe; - sub.unsubscribe = function () { - origUnsubscribe.call( sub ); - postalSocket.unsubscribe( { channel : sub.channel, topic : sub.topic } ); - }; - postalSocket.subscribe( { channel : sub.channel, topic : sub.topic } ); - return sub; - }; - - channel.topic = function ( topic ) { - if ( topic === channel._topic ) { - return this; - } - return new SocketChannel( this.channel, topic ); - }; - - return channel; - }; - -} )); \ No newline at end of file diff --git a/example/node/client/js/infrastructure/router.js b/example/node/client/js/infrastructure/router.js deleted file mode 100644 index 82f3d49..0000000 --- a/example/node/client/js/infrastructure/router.js +++ /dev/null @@ -1,53 +0,0 @@ -define( [ - 'jquery', - 'backbone', - 'bus' -], function ( $, Backbone, bus ) { - - return Backbone.Router.extend( { - routes : { - "" : "home", - "requests" : "requests", - "wiretap" : "wiretap", - "*anything" : "redirect" - }, - - initialize : function () { - var self = this; - _.bindAll( self ); - - $( document ).delegate( "a.ps-nav", "click", function ( e ) { - e.preventDefault(); - self.navigate( $( this ).attr( 'href' ), { trigger : true } ); - } ); - bus.router.publish( "initialized" ); - - }, - - activateUI : function ( uiName, context ) { - bus.viewManager.publish( { - topic : "ui.show", - data : { - name : uiName, - context : context - } - } ); - }, - - home : function () { - this.activateUI( "homeUI" ); - }, - - requests : function () { - this.activateUI( "searchRequestUI" ); - }, - - wiretap : function () { - this.activateUI( "wireTapLogUI" ); - }, - - redirect : function () { - this.navigate( "/", { trigger : true } ); - } - } ); -} ); \ No newline at end of file diff --git a/example/node/client/js/infrastructure/view-manager.js b/example/node/client/js/infrastructure/view-manager.js deleted file mode 100644 index 2508575..0000000 --- a/example/node/client/js/infrastructure/view-manager.js +++ /dev/null @@ -1,121 +0,0 @@ -define( [ - 'underscore', - 'bus' -], function ( _, bus ) { - var ViewManager = function () { - this.views = {}; // holds the views that are registered with the manager - this.UI = {}; // holds the UI configurations that are defined - this.priorContext = undefined; // holds the name of the last UI configuration - }; - - //---------------------------------------------------------------------------- - // registerView - registers a view with the manager, under the name provided. - // The handle to the constructor function (second arg) is used to create an - // instance of the view the first time getInstance is called. The rendered - // and visible booleans are used by the ViewManager to track state of the view. - // The getInstance call can take an options object. If options.forceNew = true, - // then the ViewManager will create a new instance of the view. If options.args - // exists, it will be passed into the constructor function of the view. - //---------------------------------------------------------------------------- - ViewManager.prototype.registerView = function ( name, viewCtor ) { - this.views[name] = { - rendered : false, - visible : false, - getInstance : (function () { - var _instance; - return function ( options ) { - var _options = options || {}; - if ( !_instance || _options.forceNew ) { - _instance = new viewCtor( _options.args || {} ); - } - return _instance; - } - })() - } - }; - - ViewManager.prototype.registerViews = function ( views ) { - _.each( views, function ( view ) { - this.registerView( view.name, view.ctor ); - }, this ); - }; - - //---------------------------------------------------------------------------- - // defineUI - defines a UI configuration, which is effectively a named group - // of views that need to be stood up, in order. The first argument is the UI - // name, second arg is the array of view names (in the order they need to be - // instantiated/rendered/shown) - //---------------------------------------------------------------------------- - ViewManager.prototype.defineUI = function ( name, dependencies, options ) { - var self = this; - self.UI[ name ] = { - options : options || {}, - dependencies : dependencies, - activate : function ( data ) { - data = data || {}; - data.priorContext = self.priorContext; - data.targetContext = name; - - if ( !this.options.noHide ) { - // hide anything visible that's not in the dependencies for this UI configuration - var shouldHide = _.reduce( self.views, function ( memo, val, key ) { - if ( val.visible && !_.include( this.dependencies, key ) ) { - memo.push( key ); - } - return memo; - }, [], this ); - - _.each( shouldHide, function ( viewName ) { - var instance = self.views[ viewName ].getInstance(); - if ( instance.hide ) { - instance.hide(); - } - self.views[ viewName ].visible = false; - } ); - } - - // set up, render & show the dependencies for this UI configuration - _.each( this.dependencies, function ( viewName ) { - var instance = self.views[viewName].getInstance( data ); - if ( !self.views[viewName].rendered ) { - instance.render( data ); - self.views[viewName].rendered = true; - } - if ( !self.views[viewName].visible ) { - if ( instance.show ) { - instance.show( data ); - } - self.views[viewName].visible = true; - } - - if ( instance.update ) { - instance.update( data ); - } - } ); - self.priorContext = name; - } - }; - }; - - ViewManager.prototype.defineUIs = function ( uis ) { - _.each( uis, function ( ui ) { - this.defineUI( ui.name, ui.dependencies, ui.options ); - }, this ); - }; - - ViewManager.prototype.addViewToUI = function ( uiName, viewName, viewCtor ) { - var uis = _.isArray( uiName ) ? uiName : [ uiName ]; - - if ( !this.views[ viewName ] ) { - this.registerView( viewName, viewCtor ); - } - - _.each( uis, function ( ui ) { - if ( this.UI[ ui ] ) { - this.UI[ ui ].dependencies.push( viewName ); - } - }, this ); - }; - - return ViewManager; -} ); \ No newline at end of file diff --git a/example/node/client/js/lib/amplify.js b/example/node/client/js/lib/amplify.js deleted file mode 100644 index 7394022..0000000 --- a/example/node/client/js/lib/amplify.js +++ /dev/null @@ -1,360 +0,0 @@ -/*! - * AmplifyJS 1.0.0 - Core, Store, Request - * - * Copyright 2011 appendTo LLC. (http://appendto.com/team) - * Dual licensed under the MIT or GPL licenses. - * http://appendto.com/open-source-licenses - * - * http://amplifyjs.com - */ -(function ( a, b, c ) { - typeof define == "function" && define.amd ? define( ["jquery"], function ( d ) { - return c( d, a, b ) - } ) : c( a.jQuery, a, b ) -})( this, document, function ( a, b, c, d ) { - return function ( a, b ) { - var c = [].slice, d = {}, e = a.amplify = {publish : function ( a ) { - var b = c.call( arguments, 1 ), e, f, g, h = 0, i; - if ( !d[a] ) { - return!0; - } - e = d[a].slice(); - for ( g = e.length; h < g; h++ ) { - f = e[h], i = f.callback.apply( f.context, b ); - if ( i === !1 ) { - break - } - } - return i !== !1 - }, subscribe : function ( a, b, c, e ) { - arguments.length === 3 && typeof c == "number" && (e = c, c = b, b = null), arguments.length === 2 && (c = b, b = null), e = e || 10; - var f = 0, g = a.split( /\s/ ), h = g.length, i; - for ( ; f < h; f++ ) { - a = g[f], i = !1, d[a] || (d[a] = []); - var j = d[a].length - 1, k = {callback : c, context : b, priority : e}; - for ( ; j >= 0; j-- ) { - if ( d[a][j].priority <= e ) { - d[a].splice( j + 1, 0, k ), i = !0; - break - } - } - i || d[a].unshift( k ) - } - return c - }, unsubscribe : function ( a, b ) { - if ( !d[a] ) { - return; - } - var c = d[a].length, e = 0; - for ( ; e < c; e++ ) { - if ( d[a][e].callback === b ) { - d[a].splice( e, 1 ); - break - } - } - }} - }( this ), function ( a, b ) { - function f( a, c ) { - d.addType( a, function ( f, g, h ) { - var i, j, k, l, m = g, n = (new Date).getTime(); - if ( !f ) { - m = {}, l = [], k = 0; - try { - f = c.length; - while ( f = c.key( k++ ) ) { - e.test( f ) && (j = JSON.parse( c.getItem( f ) ), j.expires && j.expires <= n ? l.push( f ) : m[f.replace( e, "" )] = j.data); - } - while ( f = l.pop() ) { - c.removeItem( f ) - } - } catch ( o ) { - } - return m - } - f = "__amplify__" + f; - if ( g === b ) { - i = c.getItem( f ), j = i ? JSON.parse( i ) : {expires : -1}; - if ( !(j.expires && j.expires <= n) ) { - return j.data; - } - c.removeItem( f ) - } else if ( g === null ) { - c.removeItem( f ); - } else { - j = JSON.stringify( {data : g, expires : h.expires ? n + h.expires : null} ); - try { - c.setItem( f, j ) - } catch ( o ) { - d[a](); - try { - c.setItem( f, j ) - } catch ( o ) { - throw d.error() - } - } - } - return m - } ) - } - - var d = a.store = function ( a, b, c, e ) { - var e = d.type; - return c && c.type && c.type in d.types && (e = c.type), d.types[e]( a, b, c || {} ) - }; - d.types = {}, d.type = null, d.addType = function ( a, b ) { - d.type || (d.type = a), d.types[a] = b, d[a] = function ( b, c, e ) { - return e = e || {}, e.type = a, d( b, c, e ) - } - }, d.error = function () { - return"amplify.store quota exceeded" - }; - var e = /^__amplify__/; - for ( var g in{localStorage : 1, sessionStorage : 1} ) { - try { - window[g].getItem && f( g, window[g] ) - } catch ( h ) { - } - } - if ( !d.types.localStorage && window.globalStorage ) { - try { - f( "globalStorage", window.globalStorage[window.location.hostname] ), d.type === "sessionStorage" && (d.type = "globalStorage") - } catch ( h ) { - } - } - (function () { - if ( d.types.localStorage ) { - return; - } - var a = c.createElement( "div" ), e = "amplify"; - a.style.display = "none", c.getElementsByTagName( "head" )[0].appendChild( a ); - try { - a.addBehavior( "#default#userdata" ), a.load( e ) - } catch ( f ) { - a.parentNode.removeChild( a ); - return - } - d.addType( "userData", function ( c, f, g ) { - a.load( e ); - var h, i, j, k, l, m = f, n = (new Date).getTime(); - if ( !c ) { - m = {}, l = [], k = 0; - while ( h = a.XMLDocument.documentElement.attributes[k++] ) { - i = JSON.parse( h.value ), i.expires && i.expires <= n ? l.push( h.name ) : m[h.name] = i.data; - } - while ( c = l.pop() ) { - a.removeAttribute( c ); - } - return a.save( e ), m - } - c = c.replace( /[^-._0-9A-Za-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u37f-\u1fff\u200c-\u200d\u203f\u2040\u2070-\u218f]/g, "-" ), c = c.replace( /^-/, "_-" ); - if ( f === b ) { - h = a.getAttribute( c ), i = h ? JSON.parse( h ) : {expires : -1}; - if ( !(i.expires && i.expires <= n) ) { - return i.data; - } - a.removeAttribute( c ) - } else { - f === null ? a.removeAttribute( c ) : (j = a.getAttribute( c ), i = JSON.stringify( {data : f, expires : g.expires ? n + g.expires : null} ), a.setAttribute( c, i )); - } - try { - a.save( e ) - } catch ( o ) { - j === null ? a.removeAttribute( c ) : a.setAttribute( c, j ), d.userData(); - try { - a.setAttribute( c, i ), a.save( e ) - } catch ( o ) { - throw j === null ? a.removeAttribute( c ) : a.setAttribute( c, j ), d.error() - } - } - return m - } ) - })(), function () { - function e( a ) { - return a === b ? b : JSON.parse( JSON.stringify( a ) ) - } - - var a = {}, c = {}; - d.addType( "memory", function ( d, f, g ) { - return d ? f === b ? e( a[d] ) : (c[d] && (clearTimeout( c[d] ), delete c[d]), f === null ? (delete a[d], null) : (a[d] = f, g.expires && (c[d] = setTimeout( function () { - delete a[d], delete c[d] - }, g.expires )), f)) : e( a ) - } ) - }() - }( this.amplify = this.amplify || {} ), function ( a, b ) { - function c() { - } - - function d( a ) { - return{}.toString.call( a ) === "[object Function]" - } - - function e( a ) { - var b = !1; - return setTimeout( function () { - b = !0 - }, 1 ), function () { - var c = this, d = arguments; - b ? a.apply( c, d ) : setTimeout( function () { - a.apply( c, d ) - }, 1 ) - } - } - - a.request = function ( b, f, g ) { - var h = b || {}; - typeof h == "string" && (d( f ) && (g = f, f = {}), h = {resourceId : b, data : f || {}, success : g}); - var i = {abort : c}, j = a.request.resources[h.resourceId], k = h.success || c, l = h.error || c; - h.success = e( function ( b, c ) { - c = c || "success", a.publish( "request.success", h, b, c ), a.publish( "request.complete", h, b, c ), k( b, c ) - } ), h.error = e( function ( b, c ) { - c = c || "error", a.publish( "request.error", h, b, c ), a.publish( "request.complete", h, b, c ), l( b, c ) - } ); - if ( !j ) { - throw h.resourceId ? "amplify.request: unknown resourceId: " + h.resourceId : "amplify.request: no resourceId provided"; - } - if ( !a.publish( "request.before", h ) ) { - h.error( null, "abort" ); - return - } - return a.request.resources[h.resourceId]( h, i ), i - }, a.request.types = {}, a.request.resources = {}, a.request.define = function ( b, c, d ) { - if ( typeof c == "string" ) { - if ( !(c in a.request.types) ) { - throw"amplify.request.define: unknown type: " + c; - } - d.resourceId = b, a.request.resources[b] = a.request.types[c]( d ) - } else { - a.request.resources[b] = c - } - } - }( amplify ), function ( a, b, c ) { - var d = ["status", "statusText", "responseText", "responseXML", "readyState"], e = /\{([^\}]+)\}/g; - a.request.types.ajax = function ( e ) { - return e = b.extend( {type : "GET"}, e ), function ( f, g ) { - function n( a, e ) { - b.each( d, function ( a, b ) { - try { - m[b] = h[b] - } catch ( c ) { - } - } ), /OK$/.test( m.statusText ) && (m.statusText = "success"), a === c && (a = null), l && (e = "abort"), /timeout|error|abort/.test( e ) ? m.error( a, e ) : m.success( a, e ), n = b.noop - } - - var h, i = e.url, j = g.abort, k = b.extend( !0, {}, e, {data : f.data} ), l = !1, m = {readyState : 0, setRequestHeader : function ( a, b ) { - return h.setRequestHeader( a, b ) - }, getAllResponseHeaders : function () { - return h.getAllResponseHeaders() - }, getResponseHeader : function ( a ) { - return h.getResponseHeader( a ) - }, overrideMimeType : function ( a ) { - return h.overrideMideType( a ) - }, abort : function () { - l = !0; - try { - h.abort() - } catch ( a ) { - } - n( null, "abort" ) - }, success : function ( a, b ) { - f.success( a, b ) - }, error : function ( a, b ) { - f.error( a, b ) - }}; - a.publish( "request.ajax.preprocess", e, f, k, m ), b.extend( k, {success : function ( a, b ) { - n( a, b ) - }, error : function ( a, b ) { - n( null, b ) - }, beforeSend : function ( b, c ) { - h = b, k = c; - var d = e.beforeSend ? e.beforeSend.call( this, m, k ) : !0; - return d && a.publish( "request.before.ajax", e, f, k, m ) - }} ), b.ajax( k ), g.abort = function () { - m.abort(), j.call( this ) - } - } - }, a.subscribe( "request.ajax.preprocess", function ( a, c, d ) { - var f = [], g = d.data; - if ( typeof g == "string" ) { - return; - } - g = b.extend( !0, {}, a.data, g ), d.url = d.url.replace( e, function ( a, b ) { - if ( b in g ) { - return f.push( b ), g[b] - } - } ), b.each( f, function ( a, b ) { - delete g[b] - } ), d.data = g - } ), a.subscribe( "request.ajax.preprocess", function ( a, c, d ) { - var e = d.data, f = a.dataMap; - if ( !f || typeof e == "string" ) { - return; - } - b.isFunction( f ) ? d.data = f( e ) : (b.each( a.dataMap, function ( a, b ) { - a in e && (e[b] = e[a], delete e[a]) - } ), d.data = e) - } ); - var f = a.request.cache = {_key : function ( a, b, c ) { - function g() { - return c.charCodeAt( e++ ) << 24 | c.charCodeAt( e++ ) << 16 | c.charCodeAt( e++ ) << 8 | c.charCodeAt( e++ ) << 0 - } - - c = b + c; - var d = c.length, e = 0, f = g(); - while ( e < d ) { - f ^= g(); - } - return"request-" + a + "-" + f - }, _default : function () { - var a = {}; - return function ( b, c, d, e ) { - var g = f._key( c.resourceId, d.url, d.data ), h = b.cache; - if ( g in a ) { - return e.success( a[g] ), !1; - } - var i = e.success; - e.success = function ( b ) { - a[g] = b, typeof h == "number" && setTimeout( function () { - delete a[g] - }, h ), i.apply( this, arguments ) - } - } - }()}; - a.store && (b.each( a.store.types, function ( b ) { - f[b] = function ( c, d, e, g ) { - var h = f._key( d.resourceId, e.url, e.data ), i = a.store[b]( h ); - if ( i ) { - return e.success( i ), !1; - } - var j = g.success; - g.success = function ( d ) { - a.store[b]( h, d, {expires : c.cache.expires} ), j.apply( this, arguments ) - } - } - } ), f.persist = f[a.store.type]), a.subscribe( "request.before.ajax", function ( a ) { - var b = a.cache; - if ( b ) { - return b = b.type || b, f[b in f ? b : "_default"].apply( this, arguments ) - } - } ), a.request.decoders = {jsend : function ( a, b, c, d, e ) { - a.status === "success" ? d( a.data ) : a.status === "fail" ? e( a.data, "fail" ) : a.status === "error" && (delete a.status, e( a, "error" )) - }}, a.subscribe( "request.before.ajax", function ( c, d, e, f ) { - function j( a, b ) { - g( a, b ) - } - - function k( a, b ) { - h( a, b ) - } - - var g = f.success, h = f.error, i = b.isFunction( c.decoder ) ? c.decoder : c.decoder in a.request.decoders ? a.request.decoders[c.decoder] : a.request.decoders._default; - if ( !i ) { - return; - } - f.success = function ( a, b ) { - i( a, b, f, j, k ) - }, f.error = function ( a, b ) { - i( a, b, f, j, k ) - } - } ) - }( amplify, jQuery ), amplify -} ) \ No newline at end of file diff --git a/example/node/client/js/lib/backbone.js b/example/node/client/js/lib/backbone.js deleted file mode 100644 index 8b5f909..0000000 --- a/example/node/client/js/lib/backbone.js +++ /dev/null @@ -1,710 +0,0 @@ -// Backbone.js 0.9.2 - -// (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc. -// Backbone may be freely distributed under the MIT license. -// For all details and documentation: -// http://backbonejs.org -(function ( h, g ) { - typeof exports !== "undefined" ? g( h, exports, require( "underscore" ) ) : typeof define === "function" && define.amd ? define( ["underscore", "jquery", "exports"], function ( f, i, p ) { - h.Backbone = g( h, p, f, i ) - } ) : h.Backbone = g( h, {}, h._, h.jQuery || h.Zepto || h.ender ) -})( this, function ( h, g, f, i ) { - var p = h.Backbone, y = Array.prototype.slice, z = Array.prototype.splice; - g.VERSION = "0.9.2"; - g.setDomLibrary = function ( a ) { - i = a - }; - g.noConflict = function () { - h.Backbone = p; - return g - }; - g.emulateHTTP = false; - g.emulateJSON = false; - var q = /\s+/, l = g.Events = - {on : function ( a, b, c ) { - var d, e, f, g, j; - if ( !b ) { - return this; - } - a = a.split( q ); - for ( d = this._callbacks || (this._callbacks = {}); e = a.shift(); ) { - f = (j = d[e]) ? j.tail : {}, f.next = g = {}, f.context = c, f.callback = b, d[e] = {tail : g, next : j ? j.next : f}; - } - return this - }, off : function ( a, b, c ) { - var d, e, k, g, j, h; - if ( e = this._callbacks ) { - if ( !a && !b && !c ) { - return delete this._callbacks, this; - } - for ( a = a ? a.split( q ) : f.keys( e ); d = a.shift(); ) { - if ( k = e[d], delete e[d], k && (b || c) ) { - for ( g = k.tail; (k = k.next) !== g; ) { - if ( j = k.callback, h = k.context, b && j !== b || c && h !== c ) { - this.on( d, j, h ); - } - } - } - } - return this - } - }, - trigger : function ( a ) { - var b, c, d, e, f, g; - if ( !(d = this._callbacks) ) { - return this; - } - f = d.all; - a = a.split( q ); - for ( g = y.call( arguments, 1 ); b = a.shift(); ) { - if ( c = d[b] ) { - for ( e = c.tail; (c = c.next) !== e; ) { - c.callback.apply( c.context || this, g ); - } - } - if ( c = f ) { - e = c.tail; - for ( b = [b].concat( g ); (c = c.next) !== e; ) { - c.callback.apply( c.context || this, b ) - } - } - } - return this - }}; - l.bind = l.on; - l.unbind = l.off; - var o = g.Model = function ( a, b ) { - var c; - a || (a = {}); - b && b.parse && (a = this.parse( a )); - if ( c = n( this, "defaults" ) ) { - a = f.extend( {}, c, a ); - } - if ( b && b.collection ) { - this.collection = b.collection; - } - this.attributes = {}; - this._escapedAttributes = {}; - this.cid = f.uniqueId( "c" ); - this.changed = {}; - this._silent = {}; - this._pending = {}; - this.set( a, {silent : true} ); - this.changed = {}; - this._silent = {}; - this._pending = {}; - this._previousAttributes = f.clone( this.attributes ); - this.initialize.apply( this, arguments ) - }; - f.extend( o.prototype, l, {changed : null, _silent : null, _pending : null, idAttribute : "id", initialize : function () { - }, toJSON : function () { - return f.clone( this.attributes ) - }, get : function ( a ) { - return this.attributes[a] - }, escape : function ( a ) { - var b; - if ( b = this._escapedAttributes[a] ) { - return b; - } - b = this.get( a ); - return this._escapedAttributes[a] = f.escape( b == null ? "" : "" + b ) - }, has : function ( a ) { - return this.get( a ) != null - }, set : function ( a, b, c ) { - var d, e; - f.isObject( a ) || a == null ? (d = a, c = b) : (d = {}, d[a] = b); - c || (c = {}); - if ( !d ) { - return this; - } - if ( d instanceof o ) { - d = d.attributes; - } - if ( c.unset ) { - for ( e in d ) { - d[e] = void 0; - } - } - if ( !this._validate( d, c ) ) { - return false; - } - if ( this.idAttribute in d ) { - this.id = d[this.idAttribute]; - } - var b = c.changes = {}, g = this.attributes, h = this._escapedAttributes, j = this._previousAttributes || - {}; - for ( e in d ) { - a = d[e]; - if ( !f.isEqual( g[e], a ) || c.unset && f.has( g, e ) ) { - delete h[e], (c.silent ? this._silent : b)[e] = true; - } - c.unset ? delete g[e] : g[e] = a; - !f.isEqual( j[e], a ) || f.has( g, e ) != f.has( j, e ) ? (this.changed[e] = a, c.silent || (this._pending[e] = true)) : (delete this.changed[e], delete this._pending[e]) - } - c.silent || this.change( c ); - return this - }, unset : function ( a, b ) { - (b || (b = {})).unset = true; - return this.set( a, null, b ) - }, clear : function ( a ) { - (a || (a = {})).unset = true; - return this.set( f.clone( this.attributes ), a ) - }, fetch : function ( a ) { - var a = - a ? f.clone( a ) : {}, b = this, c = a.success; - a.success = function ( d, e, f ) { - if ( !b.set( b.parse( d, f ), a ) ) { - return false; - } - c && c( b, d ) - }; - a.error = g.wrapError( a.error, b, a ); - return(this.sync || g.sync).call( this, "read", this, a ) - }, save : function ( a, b, c ) { - var d, e; - f.isObject( a ) || a == null ? (d = a, c = b) : (d = {}, d[a] = b); - c = c ? f.clone( c ) : {}; - if ( c.wait ) { - if ( !this._validate( d, c ) ) { - return false; - } - e = f.clone( this.attributes ) - } - a = f.extend( {}, c, {silent : true} ); - if ( d && !this.set( d, c.wait ? a : c ) ) { - return false; - } - var k = this, h = c.success; - c.success = function ( a, b, e ) { - b = k.parse( a, e ); - c.wait && (delete c.wait, b = f.extend( d || {}, b )); - if ( !k.set( b, c ) ) { - return false; - } - h ? h( k, a ) : k.trigger( "sync", k, a, c ) - }; - c.error = g.wrapError( c.error, k, c ); - b = this.isNew() ? "create" : "update"; - b = (this.sync || g.sync).call( this, b, this, c ); - c.wait && this.set( e, a ); - return b - }, destroy : function ( a ) { - var a = a ? f.clone( a ) : {}, b = this, c = a.success, d = function () { - b.trigger( "destroy", b, b.collection, a ) - }; - if ( this.isNew() ) { - return d(), false; - } - a.success = function ( e ) { - a.wait && d(); - c ? c( b, e ) : b.trigger( "sync", b, e, a ) - }; - a.error = g.wrapError( a.error, b, a ); - var e = (this.sync || - g.sync).call( this, "delete", this, a ); - a.wait || d(); - return e - }, url : function () { - var a = n( this, "urlRoot" ) || n( this.collection, "url" ) || t(); - return this.isNew() ? a : a + (a.charAt( a.length - 1 ) == "/" ? "" : "/") + encodeURIComponent( this.id ) - }, parse : function ( a ) { - return a - }, clone : function () { - return new this.constructor( this.attributes ) - }, isNew : function () { - return this.id == null - }, change : function ( a ) { - a || (a = {}); - var b = this._changing; - this._changing = true; - for ( var c in this._silent ) { - this._pending[c] = true; - } - var d = f.extend( {}, a.changes, this._silent ); - this._silent = {}; - for ( c in d ) { - this.trigger( "change:" + c, this, this.get( c ), a ); - } - if ( b ) { - return this; - } - for ( ; !f.isEmpty( this._pending ); ) { - this._pending = {}; - this.trigger( "change", this, a ); - for ( c in this.changed ) { - !this._pending[c] && !this._silent[c] && delete this.changed[c]; - } - this._previousAttributes = f.clone( this.attributes ) - } - this._changing = false; - return this - }, hasChanged : function ( a ) { - return!arguments.length ? !f.isEmpty( this.changed ) : f.has( this.changed, a ) - }, changedAttributes : function ( a ) { - if ( !a ) { - return this.hasChanged() ? f.clone( this.changed ) : - false; - } - var b, c = false, d = this._previousAttributes, e; - for ( e in a ) { - if ( !f.isEqual( d[e], b = a[e] ) ) { - (c || (c = {}))[e] = b; - } - } - return c - }, previous : function ( a ) { - return!arguments.length || !this._previousAttributes ? null : this._previousAttributes[a] - }, previousAttributes : function () { - return f.clone( this._previousAttributes ) - }, isValid : function () { - return!this.validate( this.attributes ) - }, _validate : function ( a, b ) { - if ( b.silent || !this.validate ) { - return true; - } - var a = f.extend( {}, this.attributes, a ), c = this.validate( a, b ); - if ( !c ) { - return true; - } - b && b.error ? - b.error( this, c, b ) : this.trigger( "error", this, c, b ); - return false - }} ); - var r = g.Collection = function ( a, b ) { - b || (b = {}); - if ( b.model ) { - this.model = b.model; - } - if ( b.comparator ) { - this.comparator = b.comparator; - } - this._reset(); - this.initialize.apply( this, arguments ); - a && this.reset( a, {silent : true, parse : b.parse} ) - }; - f.extend( r.prototype, l, {model : o, initialize : function () { - }, toJSON : function ( a ) { - return this.map( function ( b ) { - return b.toJSON( a ) - } ) - }, add : function ( a, b ) { - var c, d, e, g, h, j = {}, i = {}, l = []; - b || (b = {}); - a = f.isArray( a ) ? a.slice() : [a]; - for ( c = 0, d = - a.length; c < d; c++ ) { - if ( !(e = a[c] = this._prepareModel( a[c], b )) ) { - throw Error( "Can't add an invalid model to a collection" ); - } - g = e.cid; - h = e.id; - j[g] || this._byCid[g] || h != null && (i[h] || this._byId[h]) ? l.push( c ) : j[g] = i[h] = e - } - for ( c = l.length; c--; ) { - a.splice( l[c], 1 ); - } - for ( c = 0, d = a.length; c < d; c++ ) { - (e = a[c]).on( "all", this._onModelEvent, this ), this._byCid[e.cid] = e, e.id != null && (this._byId[e.id] = e); - } - this.length += d; - z.apply( this.models, [b.at != null ? b.at : this.models.length, 0].concat( a ) ); - this.comparator && this.sort( {silent : true} ); - if ( b.silent ) { - return this; - } - for ( c = 0, d = this.models.length; c < d; c++ ) { - if ( j[(e = this.models[c]).cid] ) { - b.index = c, e.trigger( "add", e, this, b ); - } - } - return this - }, remove : function ( a, b ) { - var c, d, e, g; - b || (b = {}); - a = f.isArray( a ) ? a.slice() : [a]; - for ( c = 0, d = a.length; c < d; c++ ) { - if ( g = this.getByCid( a[c] ) || this.get( a[c] ) ) { - delete this._byId[g.id]; - delete this._byCid[g.cid]; - e = this.indexOf( g ); - this.models.splice( e, 1 ); - this.length--; - if ( !b.silent ) { - b.index = e, g.trigger( "remove", g, this, b ); - } - this._removeReference( g ) - } - } - return this - }, push : function ( a, b ) { - a = this._prepareModel( a, b ); - this.add( a, - b ); - return a - }, pop : function ( a ) { - var b = this.at( this.length - 1 ); - this.remove( b, a ); - return b - }, unshift : function ( a, b ) { - a = this._prepareModel( a, b ); - this.add( a, f.extend( {at : 0}, b ) ); - return a - }, shift : function ( a ) { - var b = this.at( 0 ); - this.remove( b, a ); - return b - }, get : function ( a ) { - return a == null ? void 0 : this._byId[a.id != null ? a.id : a] - }, getByCid : function ( a ) { - return a && this._byCid[a.cid || a] - }, at : function ( a ) { - return this.models[a] - }, where : function ( a ) { - return f.isEmpty( a ) ? [] : this.filter( function ( b ) { - for ( var c in a ) { - if ( a[c] !== b.get( c ) ) { - return false; - } - } - return true - } ) - }, sort : function ( a ) { - a || (a = {}); - if ( !this.comparator ) { - throw Error( "Cannot sort a set without a comparator" ); - } - var b = f.bind( this.comparator, this ); - this.comparator.length == 1 ? this.models = this.sortBy( b ) : this.models.sort( b ); - a.silent || this.trigger( "reset", this, a ); - return this - }, pluck : function ( a ) { - return f.map( this.models, function ( b ) { - return b.get( a ) - } ) - }, reset : function ( a, b ) { - a || (a = []); - b || (b = {}); - for ( var c = 0, d = this.models.length; c < d; c++ ) { - this._removeReference( this.models[c] ); - } - this._reset(); - this.add( a, f.extend( {silent : true}, - b ) ); - b.silent || this.trigger( "reset", this, b ); - return this - }, fetch : function ( a ) { - a = a ? f.clone( a ) : {}; - if ( a.parse === void 0 ) { - a.parse = true; - } - var b = this, c = a.success; - a.success = function ( d, e, f ) { - b[a.add ? "add" : "reset"]( b.parse( d, f ), a ); - c && c( b, d ) - }; - a.error = g.wrapError( a.error, b, a ); - return(this.sync || g.sync).call( this, "read", this, a ) - }, create : function ( a, b ) { - var c = this, b = b ? f.clone( b ) : {}, a = this._prepareModel( a, b ); - if ( !a ) { - return false; - } - b.wait || c.add( a, b ); - var d = b.success; - b.success = function ( e, f ) { - b.wait && c.add( e, b ); - d ? d( e, f ) : e.trigger( "sync", - a, f, b ) - }; - a.save( null, b ); - return a - }, parse : function ( a ) { - return a - }, chain : function () { - return f( this.models ).chain() - }, _reset : function () { - this.length = 0; - this.models = []; - this._byId = {}; - this._byCid = {} - }, _prepareModel : function ( a, b ) { - b || (b = {}); - if ( a instanceof o ) { - if ( !a.collection ) { - a.collection = this - } - } else { - var c; - b.collection = this; - a = new this.model( a, b ); - a._validate( a.attributes, b ) || (a = false) - } - return a - }, _removeReference : function ( a ) { - this == a.collection && delete a.collection; - a.off( "all", this._onModelEvent, this ) - }, _onModelEvent : function ( a, b, c, d ) { - (a == "add" || a == "remove") && c != this || (a == "destroy" && this.remove( b, d ), b && a === "change:" + b.idAttribute && (delete this._byId[b.previous( b.idAttribute )], this._byId[b.id] = b), this.trigger.apply( this, arguments )) - }} ); - f.each( "forEach,each,map,reduce,reduceRight,find,detect,filter,select,reject,every,all,some,any,include,contains,invoke,max,min,sortBy,sortedIndex,toArray,size,first,initial,rest,last,without,indexOf,shuffle,lastIndexOf,isEmpty,groupBy".split( "," ), function ( a ) { - r.prototype[a] = function () { - return f[a].apply( f, - [this.models].concat( f.toArray( arguments ) ) ) - } - } ); - var u = g.Router = function ( a ) { - a || (a = {}); - if ( a.routes ) { - this.routes = a.routes; - } - this._bindRoutes(); - this.initialize.apply( this, arguments ) - }, A = /:\w+/g, B = /\*\w+/g, C = /[-[\]{}()+?.,\\^$|#\s]/g; - f.extend( u.prototype, l, {initialize : function () { - }, route : function ( a, b, c ) { - g.history || (g.history = new m); - f.isRegExp( a ) || (a = this._routeToRegExp( a )); - c || (c = this[b]); - g.history.route( a, f.bind( function ( d ) { - d = this._extractParameters( a, d ); - c && c.apply( this, d ); - this.trigger.apply( this, ["route:" + - b].concat( d ) ); - g.history.trigger( "route", this, b, d ) - }, this ) ); - return this - }, navigate : function ( a, b ) { - g.history.navigate( a, b ) - }, _bindRoutes : function () { - if ( this.routes ) { - var a = [], b; - for ( b in this.routes ) { - a.unshift( [b, this.routes[b]] ); - } - b = 0; - for ( var c = a.length; b < c; b++ ) { - this.route( a[b][0], a[b][1], this[a[b][1]] ) - } - } - }, _routeToRegExp : function ( a ) { - a = a.replace( C, "\\$&" ).replace( A, "([^/]+)" ).replace( B, "(.*?)" ); - return RegExp( "^" + a + "$" ) - }, _extractParameters : function ( a, b ) { - return a.exec( b ).slice( 1 ) - }} ); - var m = g.History = function () { - this.handlers = - []; - f.bindAll( this, "checkUrl" ) - }, s = /^[#\/]/, D = /msie [\w.]+/; - m.started = false; - f.extend( m.prototype, l, {interval : 50, getHash : function ( a ) { - return(a = (a ? a.location : window.location).href.match( /#(.*)$/ )) ? a[1] : "" - }, getFragment : function ( a, b ) { - if ( a == null ) { - if ( this._hasPushState || b ) { - var a = window.location.pathname, c = window.location.search; - c && (a += c) - } else { - a = this.getHash(); - } - } - a.indexOf( this.options.root ) || (a = a.substr( this.options.root.length )); - return a.replace( s, "" ) - }, start : function ( a ) { - if ( m.started ) { - throw Error( "Backbone.history has already been started" ); - } - m.started = true; - this.options = f.extend( {}, {root : "/"}, this.options, a ); - this._wantsHashChange = this.options.hashChange !== false; - this._wantsPushState = !!this.options.pushState; - this._hasPushState = !(!this.options.pushState || !window.history || !window.history.pushState); - var a = this.getFragment(), b = document.documentMode; - if ( b = D.exec( navigator.userAgent.toLowerCase() ) && (!b || b <= 7) ) { - this.iframe = i( '