Esempio n. 1
0
function configureStore() {
  const initialState = {
    prefs: new PrefState({
      logLimit: Math.max(Services.prefs.getIntPref("devtools.hud.loglimit"), 1),
    }),
    filters: new FilterState({
      error: Services.prefs.getBoolPref(PREFS.FILTER.ERROR),
      warn: Services.prefs.getBoolPref(PREFS.FILTER.WARN),
      info: Services.prefs.getBoolPref(PREFS.FILTER.INFO),
      debug: Services.prefs.getBoolPref(PREFS.FILTER.DEBUG),
      log: Services.prefs.getBoolPref(PREFS.FILTER.LOG),
      css: Services.prefs.getBoolPref(PREFS.FILTER.CSS),
      net: Services.prefs.getBoolPref(PREFS.FILTER.NET),
      netxhr: Services.prefs.getBoolPref(PREFS.FILTER.NETXHR),
    }),
    ui: new UiState({
      filterBarVisible: Services.prefs.getBoolPref(PREFS.UI.FILTER_BAR),
    })
  };

  return createStore(
    combineReducers(reducers),
    initialState,
    compose(applyMiddleware(thunk), enableBatching())
  );
}
Esempio n. 2
0
/**
 * Configure state and middleware for the Network monitor tool.
 */
function configureStore(connector, telemetry) {
  // Prepare initial state.
  const initialState = {
    filters: new Filters({
      requestFilterTypes: getFilterState(),
    }),
    requests: new Requests(),
    sort: new Sort(),
    timingMarkers: new TimingMarkers(),
    ui: UI({
      columns: getColumnState(),
      columnsData: getColumnsData(),
    }),
  };

  // Prepare middleware.
  const middleware = applyMiddleware(
    thunk,
    prefs,
    batching,
    recording(connector),
    throttling(connector),
    eventTelemetry(connector, telemetry),
  );

  return createStore(rootReducer, initialState, middleware);
}
Esempio n. 3
0
module.exports = (opts={}) => {
  const middleware = [
    task,
    thunk,
    promise,

    // Order is important: services must go last as they always
    // operate on "already transformed" actions. Actions going through
    // them shouldn't have any special fields like promises, they
    // should just be normal JSON objects.
    waitUntilService
  ];

  if (opts.history) {
    middleware.push(history(opts.history));
  }

  if (opts.middleware) {
    opts.middleware.forEach(fn => middleware.push(fn));
  }

  if (opts.log) {
    middleware.push(log);
  }

  return applyMiddleware(...middleware)(createStore);
}
Esempio n. 4
0
/**
 * Create and configure store for the Console panel. This is the place
 * where various enhancers and middleware can be registered.
 */
function configureStore(hud, options = {}) {
  const prefsService = getPrefsService(hud);
  const {
    getBoolPref,
    getIntPref,
  } = prefsService;

  const logLimit = options.logLimit
    || Math.max(getIntPref("devtools.hud.loglimit"), 1);
  const sidebarToggle = getBoolPref(PREFS.FEATURES.SIDEBAR_TOGGLE);
  const jstermCodeMirror = getBoolPref(PREFS.FEATURES.JSTERM_CODE_MIRROR);
  const jstermReverseSearch = getBoolPref(PREFS.FEATURES.JSTERM_REVERSE_SEARCH);
  const historyCount = getIntPref(PREFS.UI.INPUT_HISTORY_COUNT);

  const initialState = {
    prefs: PrefState({
      logLimit,
      sidebarToggle,
      jstermCodeMirror,
      jstermReverseSearch,
      historyCount,
    }),
    filters: FilterState({
      error: getBoolPref(PREFS.FILTER.ERROR),
      warn: getBoolPref(PREFS.FILTER.WARN),
      info: getBoolPref(PREFS.FILTER.INFO),
      debug: getBoolPref(PREFS.FILTER.DEBUG),
      log: getBoolPref(PREFS.FILTER.LOG),
      css: getBoolPref(PREFS.FILTER.CSS),
      net: getBoolPref(PREFS.FILTER.NET),
      netxhr: getBoolPref(PREFS.FILTER.NETXHR),
    }),
    ui: UiState({
      filterBarVisible: getBoolPref(PREFS.UI.FILTER_BAR),
      networkMessageActiveTabId: "headers",
      persistLogs: getBoolPref(PREFS.UI.PERSIST),
    })
  };

  // Prepare middleware.
  const middleware = applyMiddleware(
    thunk.bind(null, {prefsService, client: (options.services || {})}),
    historyPersistence,
    eventTelemetry.bind(null, options.telemetry, options.sessionId),
  );

  return createStore(
    createRootReducer(),
    initialState,
    compose(
      middleware,
      enableActorReleaser(hud),
      enableBatching(),
      enableNetProvider(hud),
      enableMessagesCacheClearing(hud),
      ensureCSSErrorReportingEnabled(hud),
    )
  );
}
add_task(function* () {
  let store = applyMiddleware(task)(createStore)(reducer);

  store.dispatch(generatorError());
  yield waitUntilState(store, () => store.getState().length === 1);
  equal(store.getState()[0].type, ERROR_TYPE, "generator errors dispatch ERROR_TYPE actions");
  equal(store.getState()[0].error, "task-middleware-error-generator", "generator errors dispatch ERROR_TYPE actions with error");
});
add_task(async function() {
  const store = applyMiddleware(task)(createStore)(reducer);

  store.dispatch(fetch1("generator"));
  await waitUntilState(store, () => store.getState().length === 1);
  equal(store.getState()[0].data, "generator",
        "task middleware async dispatches an action via generator");

  store.dispatch(fetch2("sync"));
  await waitUntilState(store, () => store.getState().length === 2);
  equal(store.getState()[1].data, "sync",
        "task middleware sync dispatches an action via sync");
});
add_task(function* () {
  let store = applyMiddleware(task)(createStore)(reducer);

  store.dispatch(comboAction());
  yield waitUntilState(store, () => store.getState().length === 3);

  equal(store.getState()[0].type, "fetchAsync-start", "Async dispatched actions in a generator task are fired");
  equal(store.getState()[1].type, "fetchAsync-end", "Async dispatched actions in a generator task are fired");
  equal(store.getState()[2].type, "fetchSync", "Return values of yielded sync dispatched actions are correct");
  equal(store.getState()[3].type, "fetch-done", "Return values of yielded async dispatched actions are correct");
  equal(store.getState()[3].data.sync.data, "sync", "Return values of dispatched sync values are correct");
  equal(store.getState()[3].data.async, "async", "Return values of dispatched async values are correct");
});
Esempio n. 8
0
module.exports = (opts={}) => {
  const middleware = [
    thunk,
    waitUntilService
  ];

  if (opts.log) {
    middleware.push(log);
  }

  if (opts.middleware) {
    opts.middleware.forEach(fn => middleware.push(fn));
  }

  return applyMiddleware(...middleware)(createStore);
}
Esempio n. 9
0
function configureStore() {
  const initialState = {
    debugTargets: new DebugTargetsState(),
    runtimes: new RuntimesState(),
    ui: getUiState(),
  };

  const middleware = applyMiddleware(thunk,
                                     debugTargetListenerMiddleware,
                                     errorLoggingMiddleware,
                                     extensionComponentDataMiddleware,
                                     tabComponentDataMiddleware,
                                     workerComponentDataMiddleware,
                                     waitUntilService);

  return createStore(rootReducer, initialState, middleware);
}
Esempio n. 10
0
/**
 * Create and configure store for the Console panel. This is the place
 * where various enhancers and middleware can be registered.
 */
function configureStore(hud, options = {}) {
  const prefsService = getPrefsService(hud);
  const {
    getBoolPref,
    getIntPref,
  } = prefsService;

  const logLimit = options.logLimit
    || Math.max(getIntPref("devtools.hud.loglimit"), 1);
  const sidebarToggle = getBoolPref(PREFS.UI.SIDEBAR_TOGGLE);

  const initialState = {
    prefs: PrefState({ logLimit, sidebarToggle }),
    filters: FilterState({
      error: getBoolPref(PREFS.FILTER.ERROR),
      warn: getBoolPref(PREFS.FILTER.WARN),
      info: getBoolPref(PREFS.FILTER.INFO),
      debug: getBoolPref(PREFS.FILTER.DEBUG),
      log: getBoolPref(PREFS.FILTER.LOG),
      css: getBoolPref(PREFS.FILTER.CSS),
      net: getBoolPref(PREFS.FILTER.NET),
      netxhr: getBoolPref(PREFS.FILTER.NETXHR),
    }),
    ui: UiState({
      filterBarVisible: getBoolPref(PREFS.UI.FILTER_BAR),
      networkMessageActiveTabId: "headers",
      persistLogs: getBoolPref(PREFS.UI.PERSIST),
    })
  };

  return createStore(
    createRootReducer(),
    initialState,
    compose(
      applyMiddleware(thunk.bind(null, {prefsService})),
      enableActorReleaser(hud),
      enableBatching(),
      enableNetProvider(hud),
      enableMessagesCacheClearing(hud),
      ensureCSSErrorReportingEnabled(hud),
    )
  );
}
Esempio n. 11
0
/**
 * Create and configure store for the Console panel. This is the place
 * where various enhancers and middleware can be registered.
 */
function configureStore(webConsoleUI, options = {}) {
  const prefsService = getPrefsService(webConsoleUI);
  const {
    getBoolPref,
    getIntPref,
  } = prefsService;

  const logLimit = options.logLimit
    || Math.max(getIntPref("devtools.hud.loglimit"), 1);
  const sidebarToggle = getBoolPref(PREFS.FEATURES.SIDEBAR_TOGGLE);
  const jstermCodeMirror = getBoolPref(PREFS.FEATURES.JSTERM_CODE_MIRROR);
  const historyCount = getIntPref(PREFS.UI.INPUT_HISTORY_COUNT);

  const initialState = {
    prefs: PrefState({
      logLimit,
      sidebarToggle,
      jstermCodeMirror,
      historyCount,
    }),
    filters: FilterState({
      error: getBoolPref(PREFS.FILTER.ERROR),
      warn: getBoolPref(PREFS.FILTER.WARN),
      info: getBoolPref(PREFS.FILTER.INFO),
      debug: getBoolPref(PREFS.FILTER.DEBUG),
      log: getBoolPref(PREFS.FILTER.LOG),
      css: getBoolPref(PREFS.FILTER.CSS),
      net: getBoolPref(PREFS.FILTER.NET),
      netxhr: getBoolPref(PREFS.FILTER.NETXHR),
    }),
    ui: UiState({
      networkMessageActiveTabId: "headers",
      persistLogs: getBoolPref(PREFS.UI.PERSIST),
      editor: getBoolPref(PREFS.UI.EDITOR),
    }),
  };

  // Prepare middleware.
  const services = (options.services || {});

  const middleware = applyMiddleware(
    thunk.bind(null, {
      prefsService,
      services,
      // Needed for the ObjectInspector
      client: {
        createObjectClient: services.createObjectClient,
        createLongStringClient: services.createLongStringClient,
        releaseActor: services.releaseActor,
      },
    }),
    historyPersistence,
    eventTelemetry.bind(null, options.telemetry, options.sessionId),
  );

  return createStore(
    createRootReducer(),
    initialState,
    compose(
      middleware,
      enableActorReleaser(webConsoleUI),
      enableBatching(),
      enableNetProvider(webConsoleUI),
      enableMessagesCacheClearing(webConsoleUI),
      ensureCSSErrorReportingEnabled(webConsoleUI),
    )
  );
}