Skip to content
This repository has been archived by the owner on May 8, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
updated kcdc2013 postal demo
  • Loading branch information
nicholascloud committed Apr 27, 2013
1 parent 23ece6e commit 0beafe8
Show file tree
Hide file tree
Showing 38 changed files with 12,592 additions and 5,064 deletions.
4 changes: 3 additions & 1 deletion kcdc13/going-postal/README.md
@@ -1,3 +1,5 @@
# Going postal: messaging with postal.js #
# Going Postal with postal.js

### Presented at KCDC 2013

In this presentation I will cover postal.js, an in-memory service bus for server- and client-side JavaScript development. I will discuss the differences between a service bus and the traditional node eventing model while demonstrating feature differences between postal.js and EventEmitter. I will then move to the browser and show how postal.js can augment client development, specifically how it works charmingly with jQuery.
9 changes: 9 additions & 0 deletions kcdc13/going-postal/demo/js/channels.js
@@ -0,0 +1,9 @@
/*global define*/
define(['postal'], function (postal) {
'use strict';
return {
global: postal.channel('global'),
categories: postal.channel('categories'),
search: postal.channel('search')
};
});
46 changes: 22 additions & 24 deletions kcdc13/going-postal/demo/js/data.js
@@ -1,7 +1,6 @@
/*global define:true*/

/*global define*/
define(['underscore'], function (_) {

'use strict';
var _offers = [
{
id: 1,
Expand Down Expand Up @@ -232,7 +231,9 @@ define(['underscore'], function (_) {

var cache = {
fetchStore: function (key, fetchData) {
if (this.hasOwnProperty(key)) return this[key];
if (this.hasOwnProperty(key)) {
return this[key];
}
var data = fetchData();
this[key] = data;
return data;
Expand All @@ -246,7 +247,7 @@ define(['underscore'], function (_) {
this.categories.push(offer.category);
this.count += 1;
};
};
}

F.prototype = {
terms: terms,
Expand All @@ -263,51 +264,48 @@ define(['underscore'], function (_) {
all: function () {
return _offers;
},
random: function (howMany) {
howMany = howMany || 3;
if (howMany > _offers.length) {
howMany = _offers.length;
}
var offers = [];
while (offers.length < howMany) {

}
},
single: function (id) {
return _.find(_offers, function (offer) {
offer.id === id;
return offer.id === id;
});
},
inCategories: function (categories) {
var offers = [];
_offers.forEach(function (offer) {
if (!categories.contains(offer.category)) return;
if (!_.contains(categories, offer.category)) {
return;
}
offers.push(offer);
});
return offers;
},
search: function (terms) {
var terms = terms.split(' ');
terms = terms.split(' ');
var result = searchResult(terms);

for (var i in _offers) {
if (!_offers.hasOwnProperty(i)) continue;
if (!_offers.hasOwnProperty(i)) {
continue;
}
var offer = _offers[i];
if (terms.indexOf(offer.category) >= 0) {
result.add(offer); continue;
}

for (var j in terms) {
if (!terms.hasOwnProperty(j)) continue;
if (!terms.hasOwnProperty(j)) {
continue;
}
var term = terms[j];

var conditions = [
(offer.name.indexOf(term) >= 0),
(offer.description.indexOf(term) >= 0)
];

if (conditions.contains(true)) {
result.add(offer); break;

if (_.contains(conditions, true)) {
result.add(offer);
break;
}
}
}
Expand All @@ -323,7 +321,7 @@ define(['underscore'], function (_) {
_offers.forEach(function (offer) {
categories.push(offer.category);
});
return _.uniq(categories.sort(), true)
return _.uniq(categories.sort(), true);
});
}
}
Expand Down
51 changes: 24 additions & 27 deletions kcdc13/going-postal/demo/js/home.js
@@ -1,35 +1,32 @@
Array.prototype.contains = function (what) {
var contains = false;
/*global requirejs, rquire*/
'use strict';

//do a strict comparison
if (typeof what !== 'function') {
this.forEach(function (item) {
if (contains) return;
contains = (item === what);
});
return contains;
}

//compare with an evaluator
this.forEach(function (item) {
if (contains) return;
contains = what(item);
});
return contains;
};

require.config({
requirejs.config({
paths: {
jquery: 'lib/jquery-1.7.2.min',
underscore: 'lib/underscore',
postal: 'lib/postal',
diagnostics: 'lib/postal.diagnostics'
'jquery': 'lib/jquery-1.9.1',
'underscore': 'lib/underscore',
'postal': 'lib/postal'
},
shim: {
'underscore': {
exports: '_'
}
}
});

require(['jquery', 'postal', 'tagCloud', 'offers', 'search'], function ($, bus) {
require([
'jquery',
'channels',
'jqueryext',
'tagCloud',
'offers',
'search'
], function ($, channels) {
$().ready(function () {
bus.channel('ready').publish({});
bus.channel('categories.changed').publish(['art']);
channels.global.publish({topic: 'ready'});
channels.categories.publish({
topic: 'categories.changed',
data: ['art']
});
});
});
15 changes: 11 additions & 4 deletions kcdc13/going-postal/demo/js/jqueryext.js
@@ -1,15 +1,22 @@
/*global define:true*/

define(['jquery'], function ($) {
'use strict';

$.fn.take = function (howMany) {
if (!howMany) return this;
if (howMany > this.length) return this;
if (!howMany) {
return this;
}
if (howMany > this.length) {
return this;
}
var arr = $.makeArray(this);
return $(arr.slice(0, howMany));
};

$.fn.skip = function (howMany) {
if (howMany > this.length) return $([]);
if (howMany > this.length) {
return $([]);
}
var arr = $.makeArray(this);
return $(arr.slice(howMany));
};
Expand Down
4 changes: 0 additions & 4 deletions kcdc13/going-postal/demo/js/lib/jquery-1.7.2.min.js

This file was deleted.

0 comments on commit 0beafe8

Please sign in to comment.