This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var amqpBindingsResolver = { | |
cache : { }, | |
compare : function ( binding, topic ) { | |
if ( this.cache[topic] && this.cache[topic][binding] ) { | |
return true; | |
} | |
// binding.replace(/\./g,"\\.") // escape actual periods | |
// .replace(/#/g, ".*") // hashes match any value | |
// .replace(/\*/g, "[A-Z,a-z,0-9]*"); // asterisks match any alpha-numeric 'word' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// FSM to handle app init concerns - 90% of the time it would have linear progression through states | |
var appInitFsm = new machina.Fsm({ | |
initialState: "uninitialized"; | |
states: { | |
uninitialized: { | |
_onEnter: function() { | |
this.transition("initializing"); | |
} | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_.mixin({ | |
groupsOf: function(list, num) { | |
if (!_.isArray(list)) { | |
list = _.toArray(list); | |
} | |
var result = []; | |
while (list.length) { | |
result.push(list.splice(0, num)); | |
} | |
return result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define([ | |
'underscore', | |
'machina' | |
], function( _, machina ){ | |
return function(config) { | |
var base = { | |
initialState: "notStarted", | |
checkIfReady: function() { | |
if(_.all(this.constraints[this.state].checkList, function(constraint) { return constraint; })) { | |
this.transition(this.constraints[this.state].nextState); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Below are FOUR possible examples of publish method signatures for the upcoming v0.6.0 release. | |
// Each one is using a simple "data" object (containing Alex's first and last name, since we were chatting as I wrote the gist) | |
// It's also worth bearing in mind that this is the top level API publish (where you don't have a handle to a channel already) | |
// you'll still be able to say var channel = postal.channel({ channel: "someChannel", topic: "someTopic" }), and then call publish off that later | |
// 1.) Single Payload, envelope is special member | |
/* | |
PROS: | |
one object to publish (data/env) | |
focus is on "DATA" being published - nice for consuming dev? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* 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(root, doc, factory) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ConnectivityFsm = ( function( $, machina, amplify ) { | |
return function( heartbeatDef ) { | |
var settings = $.extend( true, { | |
type: "GET", | |
dataType: "json", | |
timeout: 5000 | |
}, heartbeatDef ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
postal.js | |
Author: Jim Cowart | |
License: Dual licensed MIT (http://www.opensource.org/licenses/mit-license) & GPL (http://www.opensource.org/licenses/gpl-license) | |
Version 0.6.0 | |
*/ | |
(function(root, doc, factory) { | |
if (typeof define === "function" && define.amd) { | |
// AMD. Register as an anonymous module. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var slice = [].slice; | |
if (!_.deepExtend) { | |
var behavior = { | |
"*": function(obj, sourcePropKey, sourcePropVal) { | |
obj[sourcePropKey] = sourcePropVal; | |
}, | |
"object": function(obj, sourcePropKey, sourcePropVal) { | |
obj[sourcePropKey] = deepExtend(obj[sourcePropKey] || {}, sourcePropVal); | |
}, | |
"array": function(obj, sourcePropKey, sourcePropVal) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cartModule = (function(postal, $){ | |
var cartId = 0, | |
cartTemplate = "#cart-tmpl", | |
cartItemTemplate = "#cart-item-tmpl", | |
cartChildrenSelector = "#cart-list", | |
wireUpCart = function(cart) { | |
postal.subscribe("cart", "init", _.bind(cart.init,cart)); | |
postal.subscribe("cart", "item.add", function(item) { | |
var member = cart.id + "-" + item.id; |