/*
 * grouter
 * https://github.com/goliatone/grouter
 * Created with gbase.
 * Copyright (c) 2014 goliatone
 * Licensed under the MIT license.
 */
/* jshint strict: false, plusplus: true */
/*global define: false, require: false, module: false, exports: false */
(function(root, name, deps, factory) {
    "use strict";
    // Node
    if (typeof deps === 'function') {
        factory = deps;
        deps = [];
    }

    if (typeof exports === 'object') {
        module.exports = factory.apply(root, deps.map(require));
    } else if (typeof define === 'function' && 'amd' in define) {
        //require js, here we assume the file is named as the lower
        //case module name.
        define(name.toLowerCase(), deps, factory);
    } else {
        // Browser
        var d, i = 0,
            global = root,
            old = global[name],
            mod;
        while ((d = deps[i]) !== undefined) deps[i++] = root[d];
        global[name] = mod = factory.apply(global, deps);
        //Export no 'conflict module', aliases the module.
        mod.noConflict = function() {
            global[name] = old;
            return mod;
        };
    }
}(this, "GRouter", ['extend'], function(extend) {

    /*
     *
     */
    var _extend = extend;

    /**
     * Shim console, make sure that if no console
     * available calls do not generate errors.
     * @return {Object} Console shim.
     */
    var _shimConsole = function(con) {

        if (con) return con;

        con = {};
        var empty = {},
            noop = function() {},
            properties = 'memory'.split(','),
            methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' +
                'groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,' +
                'table,time,timeEnd,timeStamp,trace,warn').split(','),
            prop,
            method;

        while (method = methods.pop()) con[method] = noop;
        while (prop = properties.pop()) con[prop] = empty;

        return con;
    };


    ///////////////////////////////////////////////////
    // CONSTRUCTOR
    ///////////////////////////////////////////////////

    var options = {
        initialRoute: 'home'
    };

    /**
     * GRouter constructor
     *
     * @param  {object} config Configuration object.
     */
    var GRouter = function(config) {
        config = config || {};

        config = _extend({}, this.constructor.DEFAULTS, config);

        this.init(config);
    };

    GRouter.name = GRouter.prototype.name = 'GRouter';

    GRouter.VERSION = '0.0.0';

    /**
     * Make default options available so we
     * can override.
     */
    GRouter.DEFAULTS = options;

    ///////////////////////////////////////////////////
    // PRIVATE METHODS
    ///////////////////////////////////////////////////

    GRouter.prototype.init = function(config) {
        if (this.initialized) return;
        this.initialized = true;

        this.logger.log('GRouter Initializing', config);

        config = _extend(config, this.constructor.DEFAULTS);
        _extend(this, config);

        this.currentId = this.currentId || this.initialRoute;

        return this;
    };

    GRouter.prototype.handler = function(e) {
        var data = e.data;
        this.logger.warn('=============\nhandler\n=============', data);

        //Store the current payload.
        this.event = e;
        this.data = e.data;

        this.emit('route.' + data.scene, data);

        if (data.payload && data.payload.subscene) {
            var etype = ['route', data.scene, data.payload.subscene[0]].join('.');
            this.emit(etype, data);
        }

        this.emit('route', data);
    };

    GRouter.prototype.goto = function(id, options) {

        var oldId = this.currentId,
            isTransitioning = oldId !== id;

        /*
         * Event type fired before we exit a route.
         * Default route event is:
         * exit.home
         * goto.update or goto.change
         * goto.<SCENE_ID>.<update | change>
         */
        var exitType = isTransitioning ? 'exit.' + oldId : null,
            actionType = isTransitioning ? 'change' : 'update',
            actionSceneType = 'goto.' + id + '.' + actionType;

        this.currentId = id;

        [exitType, 'goto', 'goto.' + actionType, actionSceneType].forEach(function(type) {
            if (!type) return;

            // this.logger.info('EMIT GOTO:', type);
            this.emit(type, {
                id: id,
                old: oldId,
                isTransitioning: isTransitioning,
                //TODO: Should we rename options to payload to make it
                //consistent?!!!
                options: options
            });
        }, this);
    };

    GRouter.prototype.emit = function() {
        this.logger.warn('emit not implemented', arguments);
    };

    /**
     * Logger method, meant to be implemented by
     * mixin. As a placeholder, we use console if available
     * or a shim if not present.
     */
    GRouter.prototype.logger = _shimConsole(console);

    return GRouter;
}));
@@ -2167,23 +2167,23 @@
     var 
-options
+OPTIONS
  = %7B%0A   
@@ -2572,17 +2572,17 @@
  = '0.0.
-0
+1
 ';%0A%0A    
@@ -2681,23 +2681,23 @@
 AULTS = 
-options
+OPTIONS
 ;%0A%0A    /
@@ -3414,26 +3414,24 @@
 this.data = 
-e.
 data;%0A%0A     
@@ -3437,82 +3437,42 @@
     
-this.emit('route.' + data.scene, data);%0A%0A        if (data.payload && 
+var subscene = Keypath.get(
 data
-.
+, '
 payl
@@ -3487,32 +3487,51 @@
 cene
-) %7B%0A            var etyp
+', undefined);%0A        subscene && (subscen
 e = 
@@ -3587,17 +3587,19 @@
 oin('.')
-;
+);%0A
 %0A       
@@ -3603,55 +3603,169 @@
     
-    this.emit(etype, data);%0A        %7D%0A%0A
+%5B'route', 'route.' + data.scene, subscene%5D.forEach(function(type) %7B%0A            if (!type) return;%0A            this.logger.info('EMIT ROUTE:', type);%0A   
         
 this
@@ -3752,32 +3752,33 @@
 pe);%0A           
+ 
 this.emit('route
@@ -3771,29 +3771,44 @@
 is.emit(
-'route', data
+type, data);%0A        %7D, this
 );%0A    %7D

Refactor default handler, triggers route events.