Skip to content

Commit

Permalink
Merge pull request #118 from ifandelse/fix-memory-leak
Browse files Browse the repository at this point in the history
Fixed #95. Added JSCS for formatting. Bumped version to v1.0.3
  • Loading branch information
ifandelse committed May 7, 2015
2 parents 49a67cc + ea92a84 commit f005db2
Show file tree
Hide file tree
Showing 25 changed files with 319 additions and 145 deletions.
108 changes: 108 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
// Project Specific
"excludeFiles": [
"node_modules/**",
"coverage/**",
"lib/**"
],

"esnext": true,

// Normal jscsrc
"disallowKeywords": [
"with"
],
"disallowKeywordsOnNewLine": [
"else"
],
"disallowMixedSpacesAndTabs": "smart",
"disallowMultipleLineBreaks": true,
"disallowMultipleLineStrings": true,
"disallowMultipleSpaces": true,
"disallowMultipleVarDecl": "exceptUndefined",
"disallowNewlineBeforeBlockStatements": true,
"disallowOperatorBeforeLineBreak": [
"+",
"."
],
"disallowPaddingNewlinesInBlocks": true,
"disallowQuotedKeysInObjects": "allButReserved",
"disallowSpaceAfterObjectKeys": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpaceBeforeBinaryOperators": [
",",
":"
],
"disallowSpaceBeforePostfixUnaryOperators": true,
"disallowSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInCallExpression": true,
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowTrailingComma": true,
"disallowTrailingWhitespace": true,
"maximumLineLength": null,
"requireBlocksOnNewline": true,
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
"requireCapitalizedConstructors": true,
"requireCommaBeforeLineBreak": true,
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireDotNotation": "except_snake_case",
"requireLineFeedAtFileEnd": true,
"requireOperatorBeforeLineBreak": true,
"requirePaddingNewLinesBeforeLineComments": null,
"requireParenthesesAroundIIFE": true,
"requireSemicolons": true,
"requireSpaceAfterBinaryOperators": true,
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch"
],
"requireSpaceBeforeBinaryOperators": [
"=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=", "&=", "|=", "^=", "+=", "+", "-",
"*", "/", "%", "<<", ">>", ">>>", "&", "|", "^", "&&", "||", "===", "==", ">=", "<=", "<", ">", "!=", "!=="
],
"requireSpaceBeforeBlockStatements": true,
"requireSpaceBeforeObjectValues": true,
"requireSpaceBetweenArguments": true,
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInConditionalExpression": true,
"requireSpacesInForStatement": true,
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInNamedFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInsideArrayBrackets": "all",
"requireSpacesInsideObjectBrackets": "all",
"requireSpacesInsideParentheses": "all",
"validateIndentation": "\t",
"validateLineBreaks": "LF",
"validateQuoteMarks": {
"escape": true,
"mark": "\""
}
}
1 change: 0 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
"yui" : false, //defines globals exposed by the YUI JavaScript framework

"predef" : [ // Custom globals.
"_",
"define"
],

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postal.js",
"version": "1.0.2",
"version": "1.0.3",
"description": "Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side.",
"homepage": "https://github.com/postaljs/postal.js",
"keywords": [
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v1.0.3

* Fixed memory leak issue referred to [here](https://github.com/postaljs/postal.js/issues/95#issuecomment-99336472). Postal will not place subscriptions in the lookup cache if the `resolverNoCache` header is present on the published envelope.

## v1.0.2

* Updated lodash dependency to 3.x.
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "postal.js",
"repo": "postaljs/postal.js",
"description": "Client-side messaging library",
"version": "1.0.2",
"version": "1.0.3",
"keywords": [
"pub/sub",
"pub",
Expand Down
1 change: 0 additions & 1 deletion example/amd/js/examples.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* global $ */
define( [ "postal", "postaldiags" ], function( postal, diags ) {

// This gets you a handle to the default postal channel...
// For grins, you can get a named channel instead like this:
// var channel = postal.channel( 'DoctorWho' );
Expand Down
24 changes: 22 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ var path = require( "path" );
var pkg = require( "./package.json" );
var open = require( "open" ); //jshint ignore:line
var port = 3080;
var jshint = require( "gulp-jshint" );
var jscs = require( "gulp-jscs" );
var gulpChanged = require( "gulp-changed" );

var banner = [ "/**",
" * <%= pkg.name %> - <%= pkg.description %>",
Expand All @@ -25,7 +28,7 @@ var banner = [ "/**",

gulp.task( "combine", [ "combine.postal" ] );

gulp.task( "combine.postal", function() {
gulp.task( "combine.postal", [ "format" ], function() {
return gulp.src( [ "./src/postal.js" ] )
.pipe( header( banner, {
pkg: pkg
Expand All @@ -49,7 +52,7 @@ gulp.task( "combine.postal", function() {
.pipe( gulp.dest( "./lib/" ) );
} );

gulp.task( "combine.postal-lodash", function() {
gulp.task( "combine.postal-lodash", [ "format" ], function() {
return gulp.src( [ "./src/postal.lodash.js" ] )
.pipe( header( banner, {
pkg: pkg
Expand Down Expand Up @@ -131,3 +134,20 @@ gulp.task( "watch", [ "default", "mocha" ], function() {
gulp.watch( "src/**/*", [ "default" ] );
gulp.watch( "{lib,spec}/**/*", [ "mocha" ] );
} );

gulp.task( "jshint", function() {
return gulp.src( [ "src/**/*.js", "spec/**/*.js" ] )
.pipe( jshint() )
.pipe( jshint.reporter( "jshint-stylish" ) )
.pipe( jshint.reporter( "fail" ) );
} );

gulp.task( "format", [ "jshint" ], function() {
return gulp.src( [ "./src/**/*.js", "!node_modules/**" ] )
.pipe( jscs( {
configPath: ".jscsrc",
fix: true
} ) )
.pipe( gulpChanged( "./src", { hasChanged: gulpChanged.compareSha1Digest } ) )
.pipe( gulp.dest( "./src" ) );
} );
37 changes: 21 additions & 16 deletions lib/postal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* postal - Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side.
* Author: Jim Cowart (http://ifandelse.com)
* Version: v1.0.2
* Version: v1.0.3
* Url: http://github.com/postaljs/postal.js
* License(s): MIT
*/
Expand Down Expand Up @@ -78,7 +78,7 @@
var previous;
return function (data) {
var eq = false;
if (typeof data == 'string') {
if (typeof data === "string") {
eq = data === previous;
previous = data;
} else {
Expand Down Expand Up @@ -117,7 +117,7 @@
return this.delay(0);
},
disposeAfter: function disposeAfter(maxCalls) {
if (typeof maxCalls != 'number' || maxCalls <= 0) {
if (typeof maxCalls !== "number" || maxCalls <= 0) {
throw new Error("The value provided to disposeAfter (maxCalls) must be a number greater than zero.");
}
var self = this;
Expand Down Expand Up @@ -171,7 +171,8 @@
} else {
report = console.log;
}
this["catch"](report);
this.
catch (report);
}
return this;
},
Expand All @@ -188,7 +189,7 @@
}
},
constraint: function constraint(predicate) {
if (typeof predicate != 'function') {
if (typeof predicate !== "function") {
throw new Error("Predicate constraint must be a function");
}
this.pipeline.push(function (data, env, next) {
Expand All @@ -210,7 +211,7 @@
return this;
},
debounce: function debounce(milliseconds, immediate) {
if (typeof milliseconds != 'number') {
if (typeof milliseconds !== "number") {
throw new Error("Milliseconds must be a number");
}
this.pipeline.push(
Expand All @@ -220,7 +221,7 @@
return this;
},
delay: function delay(milliseconds) {
if (typeof milliseconds != 'number') {
if (typeof milliseconds !== "number") {
throw new Error("Milliseconds must be a number");
}
var self = this;
Expand All @@ -232,7 +233,7 @@
return this;
},
throttle: function throttle(milliseconds) {
if (typeof milliseconds != 'number') {
if (typeof milliseconds !== "number") {
throw new Error("Milliseconds must be a number");
}
var fn = function (data, env, next) {
Expand Down Expand Up @@ -363,11 +364,15 @@
}
};
}
function getCacher(topic, cache, cacheKey, done, envelope) {
function getCacher(topic, pubCache, cacheKey, done, envelope) {
var headers = envelope && envelope.headers || {};
return function (subDef) {
var cache;
if (_config.resolver.compare(subDef.topic, topic, headers)) {
cache.push(subDef);
if (!headers.resolverNoCache) {
cache = pubCache[cacheKey] = (pubCache[cacheKey] || []);
cache.push(subDef);
}
subDef.cacheKeys.push(cacheKey);
if (done) {
done(subDef);
Expand Down Expand Up @@ -397,17 +402,17 @@
};
} else {
return function (sub) {
var compared = 0,
matched = 0;
var compared = 0;
var matched = 0;
_.each(options, function (val, prop) {
compared += 1;
if (
// We use the bindings resolver to compare the options.topic to subDef.topic
(prop === "topic" && resolver.compare(sub.topic, options.topic, {
resolverNoCache: true
})) || (prop === "context" && options.context === sub._context)
})) || (prop === "context" && options.context === sub._context) ||
// Any other potential prop/value matching outside topic & context...
|| (sub[prop] === options[prop])) {
(sub[prop] === options[prop])) {
matched += 1;
}
});
Expand Down Expand Up @@ -466,9 +471,8 @@
var skipped = 0;
var activated = 0;
if (!cache) {
cache = this.cache[cacheKey] = [];
var cacherFn = getCacher(
topic, cache, cacheKey, function (candidate) {
topic, this.cache, cacheKey, function (candidate) {
if (candidate.invokeSubscriber(envelope.data, envelope)) {
activated++;
} else {
Expand Down Expand Up @@ -501,6 +505,7 @@
this.unsubscribeFor();
_config.resolver.reset();
this.subscriptions = {};
this.cache = {};
},
subscribe: function subscribe(options) {
var subscriptions = this.subscriptions;
Expand Down
Loading

0 comments on commit f005db2

Please sign in to comment.