Skip to content

Commit 2a27444

Browse files
Merge pull request #10 from designfrontier/baldwin
Enforces Number type on xhr.status
2 parents 1794f40 + 6bb15a4 commit 2a27444

18 files changed

+207
-839
lines changed

Gulpfile.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ gulp.task('publish', ['generateForPublish'], function(){
7474
});
7575

7676
gulp.task('test', function (done) {
77-
gulp.src(['public/javascripts/action*.js'])
77+
gulp.src(['public/javascripts/action*.js', 'src/cjs/*_test.js'])
7878
.pipe(karma({
7979
configFile: 'karma.conf.js'
8080
, action: 'run'
8181
}));
8282
});
8383

8484
gulp.task('develop', function (done) {
85-
gulp.src(['public/javascripts/action*.js'])
85+
gulp.src(['public/javascripts/action*.js', 'src/cjs/*_test.js'])
8686
.pipe(karma({
8787
configFile: 'karma.conf.js'
8888
, action: 'watch'

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Action",
3-
"version": "0.6.1",
3+
"version": "0.7.0",
44
"homepage": "https://github.com/designfrontier/Action",
55
"authors": [
66
"Daniel Sellers <[email protected]>"

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "action",
3-
"version": "0.6.1",
4-
"releaseName": "Antonio Banderas",
3+
"version": "0.7.0",
4+
"releaseName": "Adam Baldwin",
55
"private": true,
66
"scripts": {
77
"start": "node app.js",

public/javascripts/action.js

+70-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//TODO routing and pushstate
2-
// view rendering on routing events
31
(function(){
42
'use strict';
53

@@ -296,10 +294,10 @@
296294
};
297295
}
298296

299-
returnObject.listen('system:trace', function(emitterIDIn){
297+
returnObject.listen('system:trace', function(emitterIdIn){
300298
var that = this;
301299

302-
if(that.emitterId === emitterIDIn){
300+
if(that.emitterId === emitterIdIn){
303301
that.emit('system:addTraced', that);
304302
}
305303
}, returnObject);
@@ -550,38 +548,91 @@
550548

551549
, viewMe : function(objectIn){
552550
var that = this
553-
, newView = that.eventMe(objectIn);
551+
, _stateReady = (typeof objectIn.stateReady === 'function')
552+
, newView = that.modelMe(objectIn)
553+
, children = {};
554554

555555
if(typeof newView.render === 'undefined'){
556-
throw 'render is required for a view';
556+
that.emit('global:error', new action.Error('required param', 'render() is required for a view', that));
557+
return;
557558
}
558559

559-
newView.stateReady = function(){
560-
newView.render.apply(newView);
560+
if(typeof newView.templateId === 'undefined'){
561+
that.emit('global:error', new action.Error('required param', 'templateId is required for a view', that));
562+
return;
563+
}
564+
565+
if(typeof newView.dataId === 'undefined'){
566+
that.emit('global:error', new action.Error('required param', 'dataId is required for a view', that));
567+
return;
568+
}
569+
570+
if(typeof newView.viewId === 'undefined'){
571+
that.emit('global:error', new action.Error('required param', 'viewId is required for a view', that));
572+
return;
573+
}
574+
575+
if(_stateReady){
576+
newView.super.stateReady = function(){
577+
newView.render.apply(newView);
578+
};
579+
} else {
580+
newView.stateReady = function(){
581+
newView.render.apply(newView);
582+
};
583+
}
584+
585+
newView.super.render = newView.render;
586+
587+
//TODO: maybe render is no longer required. It defaults to executing the template on the
588+
// data and targeting the element. Instead the template, data and target (or a target elem)
589+
// events are required.
590+
591+
newView.render = function(){
592+
newView.super.render.apply(newView);
593+
newView.emit('rendered:' + newView.viewId);
594+
595+
Object.getOwnPropertyNames(children).forEach(function (childEvent) {
596+
newView.emit(childEvent, children[childEvent]);
597+
});
561598
};
562599

563600
//require event for the data
564-
newView.requiredEvent('data:set:' + newView.dataID, function(dataIn){
565-
this.viewData = dataIn;
566-
}, newView);
601+
newView.requiredEvent('data:set:' + newView.dataId, function(dataIn){
602+
this.set(dataIn);
603+
}, newView, true);
567604

568605
//required event for the template
569-
newView.requiredEvent('template:set:' + newView.templateID, function(templateIn){
606+
newView.requiredEvent('template:set:' + newView.templateId, function(templateIn){
570607
this.template = templateIn;
571-
}, newView);
608+
}, newView, true);
609+
610+
if(typeof newView.targetId !== 'undefined'){
611+
newView.requiredEvent('target:set:' + newView.targetId, function(elementIn){
612+
this.element = elementIn;
613+
});
614+
}
572615

573616
if(typeof newView.destroy === 'undefined'){
574617
newView.destroy = function(){
575618
//TODO: write this out/figure it out
576619
};
577620
}
621+
622+
newView.registerChild = function(eventIn, selectorIn){
623+
children[eventIn] = selectorIn;
624+
};
625+
626+
newView.listChildren = function(){
627+
return children;
628+
};
578629

579-
newView.listen('state:change', function(stateID){
630+
newView.listen('state:change', function(stateId){
580631
var that = this;
581632

582-
if(stateID === that.stateEvent || stateID.replace('/', '') === that.stateEvent){
583-
that.emit('template:get', that.templateID);
584-
that.emit('data:get:' + that.dataID);
633+
if(stateId === that.stateEvent || stateId.replace('/', '') === that.stateEvent){
634+
that.emit('template:get', that.templateId);
635+
that.emit('data:get:' + that.dataId);
585636
}
586637
}, newView);
587638

@@ -694,8 +745,8 @@
694745
action = action.eventMe(action);
695746

696747
//this is the template manager event system
697-
action.listen('template:get', function(templateID){
698-
action.emit('template:set:' + templateID, action.templates[templateID]);
748+
action.listen('template:get', function(templateId){
749+
action.emit('template:set:' + templateId, action.templates[templateId]);
699750
});
700751

701752
action.listen('system:addTraced', function(objIn){

public/javascripts/action.viewMe_test.js

-1
This file was deleted.

0 commit comments

Comments
 (0)