|
1 |
| -//TODO routing and pushstate |
2 |
| -// view rendering on routing events |
3 | 1 | (function(){
|
4 | 2 | 'use strict';
|
5 | 3 |
|
|
296 | 294 | };
|
297 | 295 | }
|
298 | 296 |
|
299 |
| - returnObject.listen('system:trace', function(emitterIDIn){ |
| 297 | + returnObject.listen('system:trace', function(emitterIdIn){ |
300 | 298 | var that = this;
|
301 | 299 |
|
302 |
| - if(that.emitterId === emitterIDIn){ |
| 300 | + if(that.emitterId === emitterIdIn){ |
303 | 301 | that.emit('system:addTraced', that);
|
304 | 302 | }
|
305 | 303 | }, returnObject);
|
|
550 | 548 |
|
551 | 549 | , viewMe : function(objectIn){
|
552 | 550 | var that = this
|
553 |
| - , newView = that.eventMe(objectIn); |
| 551 | + , _stateReady = (typeof objectIn.stateReady === 'function') |
| 552 | + , newView = that.modelMe(objectIn) |
| 553 | + , children = {}; |
554 | 554 |
|
555 | 555 | 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; |
557 | 558 | }
|
558 | 559 |
|
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 | + }); |
561 | 598 | };
|
562 | 599 |
|
563 | 600 | //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); |
567 | 604 |
|
568 | 605 | //required event for the template
|
569 |
| - newView.requiredEvent('template:set:' + newView.templateID, function(templateIn){ |
| 606 | + newView.requiredEvent('template:set:' + newView.templateId, function(templateIn){ |
570 | 607 | 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 | + } |
572 | 615 |
|
573 | 616 | if(typeof newView.destroy === 'undefined'){
|
574 | 617 | newView.destroy = function(){
|
575 | 618 | //TODO: write this out/figure it out
|
576 | 619 | };
|
577 | 620 | }
|
| 621 | + |
| 622 | + newView.registerChild = function(eventIn, selectorIn){ |
| 623 | + children[eventIn] = selectorIn; |
| 624 | + }; |
| 625 | + |
| 626 | + newView.listChildren = function(){ |
| 627 | + return children; |
| 628 | + }; |
578 | 629 |
|
579 |
| - newView.listen('state:change', function(stateID){ |
| 630 | + newView.listen('state:change', function(stateId){ |
580 | 631 | var that = this;
|
581 | 632 |
|
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); |
585 | 636 | }
|
586 | 637 | }, newView);
|
587 | 638 |
|
|
694 | 745 | action = action.eventMe(action);
|
695 | 746 |
|
696 | 747 | //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]); |
699 | 750 | });
|
700 | 751 |
|
701 | 752 | action.listen('system:addTraced', function(objIn){
|
|
0 commit comments