How to use the flux/lib/Dispatcher.prototype function in flux

To help you get started, we’ve selected a few flux examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wevote / WebApp / src / js / dispatcher / Dispatcher.js View on Github external
import Dispatcher from 'flux/lib/Dispatcher';
import $ajax from '../utils/service';
import { httpLog } from '../utils/logging';


Dispatcher.prototype.$ajax = $ajax;

Dispatcher.prototype.loadEndpoint = function (endpoint, data = {}) {
  if (this.$ajax instanceof Function !== true) throw new Error("$ajax handler not initialized");

  // console.log("Ajax request in Dispatcher: " + endpoint);
  return this.$ajax({
    endpoint,
    data,
    success: (res) => {
      httpLog(`AJAX Response to endpoint: ${endpoint}`);
      this.dispatch({ type: endpoint, res });
    },

    error: (err) => {
      httpLog(`AJAX ERROR Response to endpoint: ${endpoint}`);
      this.dispatch({ type: `error-${endpoint}`, err });
    },
  });
github wevote / WebApp / src / js / dispatcher / Dispatcher.js View on Github external
import Dispatcher from 'flux/lib/Dispatcher';
import $ajax from '../utils/service';
import { httpLog } from '../utils/logging';


Dispatcher.prototype.$ajax = $ajax;

Dispatcher.prototype.loadEndpoint = function (endpoint, data = {}) {
  if (this.$ajax instanceof Function !== true) throw new Error("$ajax handler not initialized");

  // console.log("Ajax request in Dispatcher: " + endpoint);
  return this.$ajax({
    endpoint,
    data,
    success: (res) => {
      httpLog(`AJAX Response to endpoint: ${endpoint}`);
      this.dispatch({ type: endpoint, res });
    },

    error: (err) => {
      httpLog(`AJAX ERROR Response to endpoint: ${endpoint}`);
      this.dispatch({ type: `error-${endpoint}`, err });