Flux threw Dispatcher is not a constructor
Asked Answered
T

2

5

I try to use jspm with reactjs. I worked fine. But when I integrated it with flux package from npm. Then it always threw Dispatcher is not a constructor error. My code as below

AppDispatcher.js

import Flux from 'flux';
export default new Flux.Dispatcher();

StoreBase.js

'use strict';

import {EventEmitter} from 'events';
import AppDispatcher from '../dispatchers/AppDispatcher';

const CHANGE_EVENT = 'change';

export default class BaseStore extends EventEmitter {
    constructor() {
        super();
    }

    subscribe(actionSubscribe) {
        this._dispatchToken = AppDispatcher.register(actionSubscribe());
    }

    get dispatchToken() {
        return this._dispatchToken;
    }

    emitChange() {
        this.emit(CHANGE_EVENT);
    }

    addChangeListener(cb) {
        this.on(CHANGE_EVENT, cb)
    }

    removeChangeListener(cb) {
        this.removeListener(CHANGE_EVENT, cb);
    }
}

I used [email protected], [email protected] and [email protected]. Could anyone help me on this?

Though answered 24/6, 2015 at 6:26 Comment(2)
have you found out why is this happening or how to solve this?Jacquerie
@Jacquerie check Ajay's answer belowKhano
T
8

If you are using Babel you can use below

import { Dispatcher } from 'flux';
const dispatcher = new Dispatcher();
export default dispatcher;
Titi answered 24/6, 2015 at 9:49 Comment(0)
A
3

You should export the Dispatcher as follows

import Flux from 'flux';
export default new Flux.Dispatcher;
Anabantid answered 24/6, 2015 at 6:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.