Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

grunt, dist, clientside, jslint

  • Loading branch information...
commit bccda090c857e2d39989212c06a66122d879ab9a 1 parent 63cdbef
@jgallen23 authored
View
115 dist/observe.js
@@ -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
8 dist/observe.min.js
@@ -0,0 +1,8 @@
+/*!
+ * observe - an event lib for node and browser
+ * v0.0.5
+ * https://github.com/jgallen23/observe
+ * copyright 2012
+ * MIT License
+*/
+if(typeof __cs=="undefined"){var __cs={map:{},libs:{},r:function(e){var t=__cs.libs[__cs.map[e]];if(!t)throw new Error(e+" not found");return t}};window.require=__cs.r}__cs.map.currie="cs6c6bca62",__cs.libs.cs6c6bca62=function(e,t,n){var r=function(e,t){var n=[];for(var r=2,i=arguments.length;r<i;++r)n.push(arguments[r]);return function(){var r=n.slice(0);for(var i=0,s=arguments.length;i<s;i++)r.push(arguments[i]);e.apply(t,r)}};return t.exports=r,t.exports||n}(__cs.r,{},{}),__cs.libs.cs168726db=function(e,t,n){var r=e("currie"),i=function(e){if(e){e._handlers={};for(var t in i.prototype)e[t]=i.prototype[t];return e}this._handlers={}};return i.prototype.on=function(e,t,n){return this._handlers[e]||(this._handlers[e]=[]),t=n?r(t,n):t,this._handlers[e].push(t),t},i.prototype.emit=function(){var e=Array.prototype.slice.call(arguments),t=e.shift();if(!this.hasHandlers(t))return;for(var n=0,r=this._handlers[t].length;n<r;n++){var i=this._handlers[t][n];i&&i.apply(this,e)}},i.prototype.off=function(e,t){if(arguments.length===0){this._handlers={};return}if(!this.hasHandlers(e))return;if(arguments.length==1){delete this._handlers[e];return}var n=this._handlers[e].indexOf(t);~n&&this._handlers[e].splice(n,1)},i.prototype.once=function(e,t,n){var r=this,i=this.on(e,function(){t.apply(n,arguments),r.off(e,i)});return i},i.prototype.hasHandlers=function(e){return!!this._handlers[e]},typeof t=="object"&&(t.exports=i),t.exports||n}(__cs.r,{},{}),window.Observe=__cs.libs.cs168726db,__cs.map.Observe="cs168726db";
View
60 grunt.js
@@ -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
14 index.js
@@ -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
10 package.json
@@ -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
18 test/index.html
@@ -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  test/mocha.opts
@@ -1 +0,0 @@
---ui tdd -G
View
10 test/observe.test.js
@@ -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();
Please sign in to comment.
Something went wrong with that request. Please try again.