This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

grunt, dist, clientside, jslint

  • Loading branch information...
jgallen23 committed Nov 6, 2012
1 parent 63cdbef commit bccda090c857e2d39989212c06a66122d879ab9a
Showing with 220 additions and 16 deletions.
  1. +115 −0 dist/observe.js
  2. +8 −0 dist/observe.min.js
  3. +60 −0 grunt.js
  4. +7 −7 index.js
  5. +7 −3 package.json
  6. +18 −0 test/index.html
  7. +0 −1 test/mocha.opts
  8. +5 −5 test/observe.test.js
View
@@ -0,0 +1,115 @@
+/*!
+ * observe - an event lib for node and browser
+ * v0.0.5
+ * https://github.com/jgallen23/observe
+ * copyright 2012
+ * MIT License
+*/
+
+//built with clientside 0.4.0 https://github.com/jgallen23/clientside
+if (typeof __cs == 'undefined') {
+ var __cs = {
+ map: {},
+ libs: {},
+ r: function(p) {
+ var mod = __cs.libs[__cs.map[p]];
+ if (!mod) {
+ throw new Error(p + ' not found');
+ }
+ return mod;
+ }
+ };
+ window.require = __cs.r;
+}
+__cs.map['currie'] = 'cs6c6bca62';
+
+//currie.js
+__cs.libs.cs6c6bca62 = (function(require, module, exports) {
+var currie = function(fn, scope) {
+ var args = [];
+ for (var i=2, len = arguments.length; i < len; ++i) {
+ args.push(arguments[i]);
+ };
+ return function() {
+ var fnArgs = args.slice(0);
+ for (var i = 0, c = arguments.length; i < c; i++) {
+ fnArgs.push(arguments[i]);
+ }
+ fn.apply(scope, fnArgs);
+ };
+}
+module.exports = currie;
+return module.exports || exports;
+})(__cs.r, {}, {});
+
+//index.js
+__cs.libs.cs168726db = (function(require, module, exports) {
+var currie = require('currie');
+var Observe = function(obj) {
+ if (obj) {
+ obj._handlers = {};
+ for (var key in Observe.prototype) {
+ obj[key] = Observe.prototype[key];
+ }
+ return obj;
+ }
+ this._handlers = {};
+};
+Observe.prototype.on = function(event, fn, context) {
+ if (!this._handlers[event]) {
+ this._handlers[event] = [];
+ }
+ fn = (context) ? currie(fn, context) : fn;
+ this._handlers[event].push(fn);
+ return fn;
+};
+Observe.prototype.emit = function() {
+ var args = Array.prototype.slice.call(arguments);
+ var event = args.shift();
+ if (!this.hasHandlers(event)) {
+ return;
+ }
+ for (var i = 0, c = this._handlers[event].length; i < c; i++) {
+ var fn = this._handlers[event][i];
+ if (fn) {
+ fn.apply(this, args);
+ }
+ }
+};
+Observe.prototype.off = function(event, handler) {
+ if (arguments.length === 0) {
+ this._handlers = {};
+ return;
+ }
+ if (!this.hasHandlers(event)) {
+ return;
+ }
+ if (arguments.length == 1) {
+ delete this._handlers[event];
+ return;
+ }
+ var index = this._handlers[event].indexOf(handler);
+ if (~index) {
+ this._handlers[event].splice(index, 1);
+ }
+};
+Observe.prototype.once = function(event, handler, context) {
+ var self = this;
+ var onceHandler = this.on(event, function() {
+ handler.apply(context, arguments);
+ self.off(event, onceHandler);
+ });
+ return onceHandler;
+};
+Observe.prototype.hasHandlers = function(event) {
+ return !! this._handlers[event];
+};
+if (typeof module === "object") {
+ module.exports = Observe;
+}
+return module.exports || exports;
+})(__cs.r, {}, {});
+
+window['Observe'] = __cs.libs.cs168726db;
+__cs.map['Observe'] = 'cs168726db';
+
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -0,0 +1,60 @@
+module.exports = function(grunt) {
+ grunt.initConfig({
+ info: '<json:package.json>',
+ meta: {
+ banner: '/*!\n'+
+ ' * <%= info.name %> - <%= info.description %>\n'+
+ ' * v<%= info.version %>\n'+
+ ' * <%= info.homepage %>\n'+
+ ' * copyright <%= info.copyright %> <%= grunt.template.today("yyyy") %>\n'+
+ ' * <%= info.license %> License\n'+
+ '*/'
+ },
+ lint: {
+ all: ['index.js', 'test/*.js']
+ },
+ clientside: {
+ main: {
+ main: 'index.js',
+ name: 'Observe',
+ output: 'dist/observe.js'
+ }
+ },
+ concat: {
+ dist: {
+ src: ['<banner>', 'dist/observe.js'],
+ dest: 'dist/observe.js'
+ },
+ },
+ min: {
+ dist: {
+ src: ['<banner>', 'dist/observe.js'],
+ dest: 'dist/observe.min.js'
+ }
+ },
+ simplemocha: {
+ all: {
+ src: 'test/**/*.test.js',
+ options: {
+ ui: 'tdd',
+ reporter: 'list',
+ growl: true
+ }
+ }
+ },
+ watch: {
+ js: {
+ files: '<config:lint.all>',
+ tasks: 'default'
+ }
+ },
+ server:{
+ port: 8000,
+ base: '.'
+ }
+ });
+ grunt.loadNpmTasks('grunt-simple-mocha');
+ grunt.loadNpmTasks('grunt-clientside');
+ grunt.registerTask('default', 'lint clientside concat min simplemocha');
+ grunt.registerTask('dev', 'server watch');
+}
View
@@ -9,7 +9,7 @@ var Observe = function(obj) {
return obj;
}
this._handlers = {};
-}
+};
Observe.prototype.on = function(event, fn, context) {
if (!this._handlers[event]) {
@@ -21,7 +21,7 @@ Observe.prototype.on = function(event, fn, context) {
return fn;
-}
+};
Observe.prototype.emit = function() {
var args = Array.prototype.slice.call(arguments);
@@ -36,10 +36,10 @@ Observe.prototype.emit = function() {
fn.apply(this, args);
}
}
-}
+};
Observe.prototype.off = function(event, handler) {
- if (arguments.length == 0) {
+ if (arguments.length === 0) {
this._handlers = {};
return;
}
@@ -58,7 +58,7 @@ Observe.prototype.off = function(event, handler) {
this._handlers[event].splice(index, 1);
}
-}
+};
Observe.prototype.once = function(event, handler, context) {
var self = this;
@@ -67,12 +67,12 @@ Observe.prototype.once = function(event, handler, context) {
self.off(event, onceHandler);
});
return onceHandler;
-}
+};
Observe.prototype.hasHandlers = function(event) {
return !! this._handlers[event];
-}
+};
if (typeof module === "object") {
module.exports = Observe;
View
@@ -4,6 +4,8 @@
"homepage": "https://github.com/jgallen23/observe",
"author": "Greg Allen <@jgaui> (http://jga.me)",
"version": "0.0.5",
+ "license": "MIT",
+ "company": "JGA",
"repository": {
"type": "git",
"url": "https://github.com/jgallen23/observe.git"
@@ -12,12 +14,14 @@
"currie": "0.0.3"
},
"devDependencies": {
- "mocha": "*"
+ "mocha": "~1.6.0",
+ "grunt-simple-mocha": "~0.2.0",
+ "grunt": "~0.3.17",
+ "grunt-clientside": "~0.1.0"
},
"main": "index.js",
"scripts": {
"test": "mocha"
},
- "bin": {
- }
+ "bin": {}
}
View
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html lang="en">
+ <meta charset="utf-8" />
+ <head>
+ <title></title>
+ </head>
+ <body>
+ <script src="../dist/observe.min.js"></script>
+ <script>
+ var ob = new Observe();
+ ob.on('test', function() {
+ console.log('emitted');
+ });
+ ob.emit('test');
+ </script>
+
+ </body>
+</html>
View
@@ -1 +0,0 @@
---ui tdd -G
View
@@ -69,12 +69,12 @@ suite('observe', function() {
this.observe = new Observe();
this.observe.on('event', this.method, this);
- }
+ };
Class.prototype.method = function(val) {
this.methodCalled = true;
this.methodContext = this;
this.methodVal = val;
- }
+ };
var cls = new Class();
cls.observe.emit('event', 123);
@@ -232,12 +232,12 @@ suite('observe', function() {
this.observe = new Observe();
this.observe.once('event', this.method, this);
- }
+ };
Klass.prototype.method = function(val) {
this.methodCalled = true;
this.methodContext = this;
this.methodVal = val;
- }
+ };
var cls = new Klass();
cls.observe.emit('event', 123);
@@ -282,7 +282,7 @@ suite('observe', function() {
test('should add to prototype', function(done) {
var Class = function() {
Observe.call(this);
- }
+ };
Observe(Class.prototype);
var cls = new Class();

0 comments on commit bccda09

Please sign in to comment.