Permalink
Browse files

Copied files over, not packaged though

  • Loading branch information...
1 parent 734c1d9 commit a307306d7bc81fc0fc140ea8db7f299e29cba68c @chubas chubas committed Jan 12, 2014
Showing with 399 additions and 28 deletions.
  1. +4 −0 README.markdown
  2. +32 −0 lib/bubbling_support.js
  3. +37 −0 lib/custom_event.js
  4. +171 −0 lib/custom_event_support.js
  5. +27 −27 { → lib}/neon.js
  6. +127 −0 lib/node_support.js
  7. +1 −1 package.json
View
@@ -13,6 +13,10 @@ Neon packs a DSL for Class creation, that helps in making programs following an
The philosophy is that it should not try to emulate other languages, so it preserves the JavaScript good parts,
but with a nicer syntax to create classes that ensure interfaces and include reusable functionality as modules.
+== Why another Class System?
+
+As the web applications are getting more complex these times, backend and frontend engineers work has fusioned, and they need to be able to establish a common language. It was created for people coming from OOP languages like Ruby to Javascript.
+
=== Usage
Interface('Editable')({
View
@@ -0,0 +1,32 @@
+BubblingSupport = Module('BubblingSupport')({
+ dispatch : function (type, data) {
+ data = data || {};
+ var event = CustomEventSupport.prototype.dispatch.call(this, type, data);
+ if (event.isPropagationStopped === false) {
+ if (this.parent && this.parent.dispatch) {
+ data.target = event.target;
+ data.currentTarget = this.parent;
+ this.parent.dispatch(event.type, data);
+ }
+ }
+ return event;
+ },
+
+ prototype : {
+ dispatch : function (type, data) {
+ data = data || {};
+
+ var event = CustomEventSupport.prototype.dispatch.call(this, type, data);
+
+ if (event.isPropagationStopped === false && event.bubbles === true) {
+ if (this.parent && this.parent.dispatch) {
+ data.target = event.target;
+ data.currentTarget = this.parent;
+ this.parent.dispatch(event.type, data);
+ }
+ }
+
+ return event;
+ }
+ }
+});
View
@@ -0,0 +1,37 @@
+Class('CustomEvent')({
+ prototype : {
+ bubbles : true,
+ cancelable : true,
+ currentTarget : null,
+ timeStamp : 0,
+ target : null,
+ type : '',
+ isPropagationStopped : false,
+ isDefaultPrevented : false,
+ isImmediatePropagationStopped : false,
+ areImmediateHandlersPrevented : false,
+ init : function init(type, data) {
+ this.type = type;
+ if (typeof data !== 'undefined') {
+ for(var property in data){
+ if (data.hasOwnProperty(property)) {
+ this[property] = data[property];
+ }
+ }
+ }
+ },
+ stopPropagation : function stopPropagation() {
+ this.isPropagationStopped = true;
+ },
+ preventDefault : function preventDefault() {
+ this.isDefaultPrevented = true;
+ },
+ stopImmediatePropagation : function stopImmediatePropagation() {
+ this.preventImmediateHandlers();
+ this.stopPropagation();
+ },
+ preventImmediateHandlers : function preventImmediateHandlers() {
+ this.areImmediateHandlersPrevented = true;
+ }
+ }
+});
View
@@ -0,0 +1,171 @@
+CustomEventSupport = Module('CustomEventSupport')({
+ eventListeners : null,
+ bind : function(type, eventHandler){
+ var found, i, listeners;
+
+ if(!this.eventListeners){
+ this.eventListeners = {};
+ }
+
+ if(!this.eventListeners[type]){
+ this.eventListeners[type] = [];
+ }
+
+ found = false;
+
+ listeners = this.eventListeners[type];
+ for (i = 0; i < listeners.length; i++){
+ if (listeners[i] === eventHandler) {
+ found = true;
+ break;
+ }
+ }
+
+ if(!found){
+ this.eventListeners[type].push(eventHandler);
+ }
+
+ return this;
+ },
+ unbind : function(type, eventHandler){
+ var i, found, listeners;
+
+ found = false;
+
+ if(!this.eventListeners){
+ this.eventListeners = {};
+ }
+
+ if(typeof eventHandler == 'undefined'){
+ this.eventListeners[type] = [];
+ }
+
+ listeners = this.eventListeners[type];
+ for (i = 0; i < listeners.length; i++) {
+ if(listeners[i] === eventHandler){
+ found = true;
+ break;
+ }
+ }
+
+ if(found){
+ this.eventListeners[type].splice(i, 1);
+ }
+
+ return this;
+ },
+ dispatch : function(type, data){
+ var event, listeners, instance, i;
+
+ if (this.eventListeners === null) {
+ this.eventListeners = {};
+ }
+
+ if (typeof data === 'undefined') {
+ data = {};
+ }
+
+ if (data.hasOwnProperty('target') === false) {
+ data.target = this;
+ }
+
+ event = new CustomEvent(type, data);
+ listeners = this.eventListeners[type] || [];
+ instance = this;
+
+ for (i = 0; i < listeners.length; i = i + 1) {
+ listeners[i].call(instance, event);
+ if (event.areImmediateHandlersPrevented === true) {
+ break;
+ }
+ }
+
+ return event;
+ },
+ prototype : {
+ eventListeners : null,
+ bind : function(type, eventHandler){
+ var found, i, listeners;
+
+ if(!this.eventListeners){
+ this.eventListeners = {};
+ }
+
+ if(!this.eventListeners[type]){
+ this.eventListeners[type] = [];
+ }
+
+ found = false;
+
+ listeners = this.eventListeners[type];
+ for (i = 0; i < listeners.length; i++) {
+ if(listeners[i] === eventHandler){
+ found = true;
+ break;
+ }
+ }
+
+ if(!found){
+ this.eventListeners[type].push(eventHandler);
+ }
+
+ return this;
+ },
+ unbind : function(type, eventHandler){
+ var i, found, listeners;
+
+ found = false;
+ i = 0;
+
+ if(!this.eventListeners){
+ this.eventListeners = {};
+ }
+
+ if(typeof eventHandler == 'undefined'){
+ this.eventListeners[type] = [];
+ }
+
+ listeners = this.eventListeners[type];
+ for (i = 0; i < listeners.length; i++) {
+ if(listeners[i] == eventHandler){
+ found = true;
+ break;
+ }
+ }
+
+ if(found){
+ this.eventListeners[type].splice(i, 1);
+ }
+
+ return this;
+ },
+ dispatch : function(type, data){
+ var event, listeners, instance, i;
+
+ if (this.eventListeners === null) {
+ this.eventListeners = {};
+ }
+
+ if (typeof data === 'undefined') {
+ data = {};
+ }
+
+ if (data.hasOwnProperty('target') === false) {
+ data.target = this;
+ }
+
+ event = new CustomEvent(type, data);
+ listeners = this.eventListeners[type] || [];
+ instance = this;
+
+ for (i = 0; i < listeners.length; i = i + 1) {
+ listeners[i].call(instance, event);
+ if (event.areImmediateHandlersPrevented === true) {
+ break;
+ }
+ }
+
+ return event;
+ }
+ }
+});
View
@@ -79,12 +79,12 @@
include : function(module) {
var property;
for (property in module) {
- if (module.hasOwnProperty(property)
- && property !== 'prototype'
- && property !== 'isModule'
- && property !== '__includedModules'
- && property !== 'include'
- && property !== 'moduleName') {
+ if (module.hasOwnProperty(property) &&
+ property !== 'prototype' &&
+ property !== 'isModule' &&
+ property !== '__includedModules' &&
+ property !== 'include' &&
+ property !== 'moduleName') {
newModule[property] = module[property];
}
}
@@ -110,12 +110,12 @@
newModule.isModule = true;
for (property in definition) {
- if (definition.hasOwnProperty(property)
- && property !== 'prototype'
- && property !== 'isModule'
- && property !== '__includedModules'
- && property !== 'include'
- && property !== 'moduleName') {
+ if (definition.hasOwnProperty(property) &&
+ property !== 'prototype' &&
+ property !== 'isModule' &&
+ property !== '__includedModules' &&
+ property !== 'include' &&
+ property !== 'moduleName') {
newModule[property] = definition[property];
}
}
@@ -141,7 +141,7 @@
};
return factory;
- };
+ };
Neon.Class = function Class(classNameOrNameSpace, className) {
var nameSpace, newClass, classFactory;
@@ -162,12 +162,12 @@
newClass.include = function(module) {
var property;
for (property in module) {
- if (module.hasOwnProperty(property)
- && property != 'prototype'
- && property != 'constructor'
- && property != 'isModule'
- && property != 'include'
- && property != 'superClass') {
+ if (module.hasOwnProperty(property) &&
+ property != 'prototype' &&
+ property != 'constructor' &&
+ property != 'isModule' &&
+ property != 'include' &&
+ property != 'superClass') {
newClass[property] = module[property];
}
}
@@ -210,8 +210,8 @@
}
}
- if (newClass.__implementedInterfaces[i].hasOwnProperty('prototype')
- && newClass.__implementedInterfaces[i].prototype) {
+ if (newClass.__implementedInterfaces[i].hasOwnProperty('prototype') &&
+ newClass.__implementedInterfaces[i].prototype) {
for (j = 0, jl = newClass.__implementedInterfaces[i].prototype.length; j < jl; j++) {
if (!newClass.prototype[newClass.__implementedInterfaces[i].prototype[j]]) {
console.log('must implement prototype ' + newClass.__implementedInterfaces[i].name);
@@ -238,12 +238,12 @@
newClass.prototype.constructor = newClass;
for (i in superClass) {
- if (superClass.hasOwnProperty(i)
- && i != 'prototype'
- && i !== 'className'
- && i !== 'superClass'
- && i !== 'include'
- && i != '__descendants') {
+ if (superClass.hasOwnProperty(i) &&
+ i != 'prototype' &&
+ i !== 'className' &&
+ i !== 'superClass' &&
+ i !== 'include'&&
+ i != '__descendants') {
newClass[i] = superClass[i];
}
}
Oops, something went wrong.

0 comments on commit a307306

Please sign in to comment.