/**
 * Notify Store
 *
 * The notifications. Essentially a log to emit events.
 */

// Requires
import {ActionTypes} from '../constants/JWConstants.js';
import {register} from 'janeswalk/dispatcher/AppDispatcher';
import 'Store' from './Store.js';

// The notifications
const _log = [];

function receiveLogEntry(message, component, level) {
  _log.push({
    time: Date.now(),
    message: message,
    level: level
  });
}

const NotifyStore = Object.assign({}, Store, {
  getLog() {
    return _log;
  },

  // Register our dispatch token as a static method
  dispatchToken: register(function(payload) {
    // Go through the various actions
    switch(payload.type) {
      // Route actions
      case ActionTypes.LOG_INFO:
        receiveLogEntry(payload.message, payload.component || 'caw', 'info');
      NotifyStore.emitChange();
      break;
      case ActionTypes.LOG_WARN:
        receiveLogEntry(payload.message, payload.component || 'caw', 'warn');
      NotifyStore.emitChange();
      break;
      case ActionTypes.LOG_ERROR:
        receiveLogEntry(payload.message, payload.component || 'caw', 'error');
      NotifyStore.emitChange();
      break;
      default:
        // do nothing
    }
  });
});

export default NotifyStore;

@@ -101,153 +101,222 @@
 rt %7B
-ActionTypes%7D from '../constants/JWConstants.js';%0Aimport %7Bregister%7D from 'janeswalk/dispatcher/AppDispatcher';%0Aimport 'Store' from '.
+register2%7D from 'janeswalk/dispatcher/AppDispatcher';%0Aimport %7BEventEmitter%7D from 'events';%0Aimport %7BActionTypes as AT%7D from 'janeswalk/constants/JWConstants';%0Aimport %7BchangeMethods%7D from 'janeswalk/utils
 /Store
-.j
 s';%0A%0A
+%0A
 // T
@@ -530,14 +530,45 @@
 %7B%7D, 
-Store,
+EventEmitter.prototype, changeMethods
  %7B%0A 
@@ -578,33 +578,86 @@
 tLog
+: 
 () 
-%7B%0A    return _log;%0A  %7D
+=%3E _log,%0A  getLogFrom: (from) =%3E _log.filter(entry =%3E entry.time %3E= from)
 ,%0A%0A 
@@ -736,152 +736,59 @@
 ster
-(function(payload) %7B%0A    // Go through the various actions%0A    switch(payload.type) %7B%0A      // Route actions%0A      case ActionTypes.LOG_INFO:%0A  
+2(%7B%0A    %5BAT.LOG_INFO%5D: (%7Bmessage, component%7D) =%3E %7B%0A
     
@@ -867,90 +867,64 @@
     
-  NotifyStore.emitChange();%0A      break;%0A      case ActionTypes.LOG_WARN:%0A   
+%7D,%0A    %5BAT.LOG_WARN%5D: (%7Bmessage, component%7D) =%3E %7B%0A
      
+ 
 rece
@@ -931,32 +931,24 @@
 iveLogEntry(
-payload.
 message, pay
@@ -940,32 +940,24 @@
 ry(message, 
-payload.
 component %7C%7C
@@ -981,85 +981,59 @@
     
-  NotifyStore.emitChange();%0A      break;%0A      case ActionTypes.LOG_ERROR:%0A  
+%7D,%0A    %5BAT.LOG_ERROR%5D: (%7Bmessage, component%7D) =%3E %7B%0A
     
@@ -1046,32 +1046,24 @@
 iveLogEntry(
-payload.
 message, pay
@@ -1055,32 +1055,24 @@
 ry(message, 
-payload.
 component %7C%7C
@@ -1097,97 +1097,89 @@
     
-  NotifyStore.emitChange();%0A      break;%0A      default:%0A        // do nothing%0A    %7D%0A  %7D);
+%7D,%0A    %5BAT.LOG_EMPTY%5D: () =%3E _log.splice(0),%0A  %7D, () =%3E NotifyStore.emitChange())
 %0A%7D);

Convert notify store to new pattern