Skip to content

Commit

Permalink
Issue #16: Add 'is_default' attribute to a screen object, set to true…
Browse files Browse the repository at this point in the history
… for the screen corresponding to default route
  • Loading branch information
lpointet committed Nov 7, 2015
1 parent b44dde0 commit 5c36fb5
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions wp-appkit/app/core/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ define(function (require) {

/**
* Triggers an info event. Use this to trigger your own App events from modules and addons.
*
*
* @param {String} info event name
* @param {JSON Object} data Data that is passed to event callback
*/
app.triggerInfo = function( info, info_data, info_callback ) {

switch ( info ) {

case 'no-content':
vent.trigger( 'info:no-content' );
break;

case 'app-launched':
var stats = Stats.getStats();
vent.trigger( 'info:app-ready', { stats: stats } );
Expand All @@ -64,20 +64,20 @@ define(function (require) {
vent.trigger( 'info:app-version-changed', { stats: stats } );
}
break;

default:
vent.trigger( 'info:' + info, info_data );
if ( info_callback != undefined ) {
info_data = _.extend( { event: 'info:' + info, id: info }, info_data );
info_callback( info_data );
}
break;

}


};

//--------------------------------------------------------------------------
//Custom pages and routes handling

Expand Down Expand Up @@ -255,18 +255,22 @@ define(function (require) {
component_id:screen_data.component_id,
item_id:screen_data.item_id,
fragment:screen_data.fragment,
is_default:screen_data.is_default,
data:screen_data.hasOwnProperty('data') ? screen_data.data : {},
global:screen_data.hasOwnProperty('global') ? screen_data.global : '',
label:screen_data.hasOwnProperty('label') ? screen_data.label : ''
};
};

/**
* Called in router.js to set the queried screen according to the current route.
* Called in region-manager.js to set the queried screen according to the current route.
* This queried screen is then pushed to history in app.addQueriedScreenToHistory().
*/
app.setQueriedScreen = function(screen_data){
queried_screen_data = formatScreenData(_.extend(screen_data,{fragment: Backbone.history.fragment}));
app.setQueriedScreen = function( screen_data ){
queried_screen_data = formatScreenData( _.extend( screen_data, {
fragment: Backbone.history.fragment,
is_default: app.router.getDefaultRoute() == '#' + Backbone.history.fragment
}));
};

app.getQueriedScreen = function(){
Expand Down Expand Up @@ -637,18 +641,18 @@ define(function (require) {
Addons.setDynamicDataFromWebService( data.addons );

if ( data.components.length === 0 ) {

app.triggerError(
'synchro:no-component',
{ type: 'ws-data', where: 'app::syncWebService', message: 'No component found for this App. Please add components to the App on WordPress side.', data: data },
cb_error
);

} else {

Utils.log( 'Components, menu items and globals retrieved from online.', { components: app.components, navigation: app.navigation, globals: app.globals } );
cb_ok();

}

} else {
Expand Down Expand Up @@ -1138,7 +1142,7 @@ define(function (require) {

//persistent defaults to false :
var persistent = options.hasOwnProperty('persistent') && options.persistent === true;

var token = WsToken.getWebServiceUrlToken( 'live-query' );
var ws_url = token + '/live-query';

Expand Down

1 comment on commit 5c36fb5

@mleroi
Copy link
Collaborator

@mleroi mleroi commented on 5c36fb5 Nov 9, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Lionel, this is great!

I'm wondering about the fact that we add this "is_default" directly to the "queried_screen_data" property.
I think (am I wrong?) that we could just do the
'#' + Backbone.history.fragment == app.router.getDefaultRoute()
thing directly in the "isDefaultScreen" template tag.

But I agree that it can also be interesting to have this kind of info directly in queried_screen_data.

My concern is mostly that if we have a "is_default" we'll soon have a "is_launch", "is_404" etc... and our queried_screen_data will look like the "wp_query" object in WP ;) Many properties that have to be handled at each screen change but are not used most of the time and (in our app case) could be retrieved dynamically only when we need it...

Maybe if we decide to keep them, a good compromise can be to have a queried_screen_data.screen_info property where we group this kind of info:
queried_screen_data.screen_info.is_default
queried_screen_data.screen_info.is_404
etc

What do you think?

Please sign in to comment.