Skip to content

Commit 4117ce2

Browse files
Merge branch 'development'
2 parents 318d369 + 81c8e11 commit 4117ce2

File tree

4 files changed

+79
-32
lines changed

4 files changed

+79
-32
lines changed

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
indent_style = space
11+
indent_size = 4

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "action",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"releaseName": "Akshay Kumar",
55
"private": true,
66
"scripts": {

public/javascripts/action.js

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var action = function(){
3535
}else{
3636
eventStack[i].call(eventDataIn, that.emitterId);
3737
}
38-
38+
3939
if(eventStack[i].once){
4040
that.silence(eventNameIn, eventStack[i].call, true, isLocal);
4141
}
@@ -179,7 +179,7 @@ var action = function(){
179179
if(typeof eventNameIn === 'object'){
180180
eventNameIn.local = true;
181181
that.listenLocal(eventNameIn);
182-
}else{
182+
}else{
183183
that.listenLocal({
184184
eventName: eventNameIn
185185
, handler: handlerIn
@@ -265,7 +265,7 @@ var action = function(){
265265
if(typeof eventNameIn === 'object'){
266266
eventNameIn.local = true;
267267
that.silence(eventNameIn);
268-
}else{
268+
}else{
269269
that.silence({
270270
eventName: eventNameIn
271271
, handler: handlerIn
@@ -373,9 +373,6 @@ var action = function(){
373373
for(key in attributeName){
374374
if(attributeName.hasOwnProperty(key)){
375375
//this attribute does not belong to the prototype. Good.
376-
377-
//TODO: maybe make this do a deep copy to prevent
378-
// pass by reference or switch to clone()
379376
if(key !== 'destroy' && key !== 'fetch' && key !== 'save' && typeof attributeName[key] !== 'function'){
380377
if(typeof attributeValue === 'object'){
381378
attributes[attributeName] = (Array.isArray(attributeName[key])) ? [] : {};
@@ -386,7 +383,7 @@ var action = function(){
386383
that.emitLocal('attribute:changed', key);
387384
} else {
388385
if(typeof that[key] === 'function' && !that.super[key]){
389-
//wrap the super version in a closure so that we can
386+
//wrap the super version in a closure so that we can
390387
// still execute it correctly
391388
that.super[key] = that[key].bind(that);
392389
}
@@ -407,7 +404,7 @@ var action = function(){
407404
that.emitLocal('attribute:changed', attributeName);
408405
} else {
409406
if(typeof that[attributeName] === 'function'){
410-
//wrap the super version in a closure so that we can
407+
//wrap the super version in a closure so that we can
411408
// still execute it correctly
412409
that.super[attributeName] = that[attributeName].bind(that);
413410
}
@@ -545,7 +542,7 @@ var action = function(){
545542
newModel.clearChanges = function(){
546543
changes = [];
547544
}
548-
545+
549546
newModel.getChanges = function(){
550547
return changes;
551548
}
@@ -558,18 +555,22 @@ var action = function(){
558555
//TODO not really working... should get rid of this thing
559556
// and all of its parameters
560557
var that = this
561-
, key;
562-
563-
setTimeout(function(){
564-
// delete me;
565-
},0); // not quite working...
566-
567-
for(key in that){
568-
// delete this[key];
569-
}
570-
571-
//TODO this still doesn't kill the attributes or changes
572-
// private data
558+
, events = that.eventStore
559+
, key
560+
, i;
561+
562+
//TODO: make this iterate over the events that have been
563+
// registered by this object and silence them
564+
// otherwise zombies.
565+
566+
// for(key in events){
567+
// for(i = 0; i < events[key].length; i++){
568+
// that.silence(key, events[key][i].call,events[key][i].once)
569+
// }
570+
// // if(that.hasOwnProperty(key)){
571+
// // delete that[key];
572+
// // }
573+
// }
573574
}
574575

575576
newModel.set(objectIn); //set the inital attributes
@@ -585,10 +586,37 @@ var action = function(){
585586
return newModel;
586587
}
587588

589+
, routeMe: function(objectIn){
590+
var that = this
591+
, routeModel = that.modelMe(objectIn)
592+
593+
, init = function(){
594+
var that = this
595+
, atags = document.querySelectorAll('a')
596+
, i = 0;
597+
598+
for(i = 0; i < atags.length; i++){
599+
atags[i].addEventListener('click', function(e){
600+
var location = this.attributes.href.textContent;
601+
602+
if(typeof that.get(location) !== 'undefined'){
603+
//trigger the route
604+
that.emit('navigate', location);
605+
e.preventDefault();
606+
}
607+
});
608+
}
609+
};
610+
611+
init();
612+
613+
return routeModel;
614+
}
615+
588616
//TODO: figure out if this is needed since the global:error...
589617
// , trace: function(emitterIdIn){
590618
// //log out the function that has the emitterId attached
591-
619+
592620
// //create the traced object/stack
593621
// action.traced = action.modelMe({
594622
// stack: []
@@ -641,14 +669,14 @@ var action = function(){
641669
action.listen('global:error', function(errorIn) {
642670
console.group('An Error occured in an object with emitterid: ' + errorIn.createdBy.emitterId);
643671
console.log('It was a ' + errorIn.type + 'error.');
644-
672+
645673
if(typeof errorIn.errorObject === 'string'){
646674
console.log('It says: ' + errorIn.errorObject);
647675
console.log('and: ' + errorIn.message);
648676
} else {
649677
console.log('It says: ' + errorIn.message);
650678
}
651-
679+
652680
console.log('The Whole Enchilada (object that caused this mess):');
653681
console.dir(errorIn.createdBy);
654682

@@ -667,6 +695,10 @@ var action = function(){
667695
// throw errorIn;
668696
});
669697

698+
document.addEventListener("DOMContentLoaded", function(){
699+
action.emit('dom:ready');
700+
});
701+
670702
//return the tweaked function
671703
return action;
672-
}(this);
704+
}(this);

readme.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
#Action!
2+
`Action!` is a front end sub/pub based framework for event based development. No more passing around dependencies, no more worrying about timing. Events free you to build apps that function they way the real world does: cause and effect.
3+
4+
Need data? Ask for it. Need to do something with that data? Listen for when it is sent back to you and do it. Need to watch for the user to do something? Listen for it and react accordingly. `Action!` embraces the asynchronicity that is the world around us to create better front end experiences and code.
5+
26

37
##Road Map
48
So there are a variety of things that need to be completed for Action! to be ready for primetime. Some of them are basic (getting statemachine working), others are more complex (build tooling for troubleshooting event stacks). I am going to keep them here and make this a living document.
59

610
###TODOs before RC
11+
0. make the destroy function silence all events registered by the object it is called on
712
0. dependency resolution integration with state machines
813
0. Figure out the testing side of event driven FED in Action
914
0. Revise the destroy function to make it really do what it needs to
1015
0. Figure out how views really work... (https://github.com/twitter/hogan.js)
11-
0. Consider web components
1216

1317
###TODOs generally
1418
0. create a prod branch and a debug branch (prod probably doesn't need the extra weight of the call stack and emitterid stuff)?
1519
0. update documentation
1620
0. example app
17-
0. simplify model set function?
1821
0. make the error output even prettier! https://developers.google.com/chrome-developer-tools/docs/console-api#consoleerrorobject_object
1922

2023
###Done
@@ -25,10 +28,11 @@ So there are a variety of things that need to be completed for Action! to be rea
2528
0. Clone/ Deep Copy in the set functions
2629
0. Build out the save function for models
2730
0. ajax resolution/integration for models
28-
31+
0. Consider web components (considered... and moved on for now)
32+
0. simplify model set function?
2933

3034
#### Release Names
31-
We'll use these guys as release names: http://en.wikipedia.org/wiki/List_of_action_film_actors
35+
We'll use these folks as release names: http://en.wikipedia.org/wiki/List_of_action_film_actors
3236

3337
in order from top left - down the column then on to the next column. If we run out we'll add more names to the list :-)
3438

@@ -41,5 +45,5 @@ in order from top left - down the column then on to the next column. If we run o
4145

4246
###Dependencies
4347
There are a few dependencies for Action to be a fully useful framework. They are (with the reasons for them):
44-
0. localForage (If you want to use the local cache. It will automatically cache all of your ajax requests in local storage and pull from them all subsequent times they are requested)
45-
0. Handlebars (a templating library)
48+
0. localForage (If you want to use the local cache. It will automatically cache all of your ajax GET requests in local storage and pull from them all subsequent times they are requested)
49+
0. Handlebars, or compatible (a templating library)

0 commit comments

Comments
 (0)