1

Here is the class with the static function

import alt from '../alt';
import Parse from 'parse';
import { ElementTypes } from '../constants/ElementTypes';

class BoardActions {

    static getDefaultElement(x, y) {
        var Element = Parse.Object.extend("Element");
        var element = new Element();
        element.set("x", x);
        element.set("y", y);
        return element;
    }
}

export default alt.createActions(BoardActions);

And this is the class who calls the static function const startElement = BoardActions.getDefaultElement(0, 3);

import alt from '../alt';
import Parse from 'parse';
import { ElementTypes } from '../constants/ElementTypes';
import BoardActions from './BoardActions';

class ProjectActions {

    createNewProject(name) {
        return (dispatch) => {
            dispatch();
            const Project = Parse.Object.extend("Project");
            const project = new Project();
            let projectObject = null;
            project.set('name', name);
            project.save().then((object) => {
                projectObject = object;
                const startElement = BoardActions.getDefaultElement(0, 3);
                startElement.set('type', ElementTypes.StartType);
                startElement.set('root', true);
                startElement.set('projectId', object.id);
                return startElement.save();
            }).then((object) => {
                this.newProjectCreated(projectObject);
            }, (error) => {
                this.parseError(error);
            });
        }
    }

}

export default alt.createActions(ProjectActions);

I get this error:

ProjectActions.js:69 Uncaught TypeError: _BoardActions2.default.getDefaultElement is not a function

What's wrong?

Edit: I use babel as transpiler.

"babel-core": "^6.5.1",
"babel-loader": "^6.2.2",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
"babel-preset-react-hmre": "^1.1.0",
"babel-preset-survivejs-kanban": "^0.3.3",
zeiteisen
  • 7,078
  • 5
  • 50
  • 68

1 Answers1

1

EDITED (since you edited your question):

In the second file you are importing

import BoardActions from './BoardActions';

Which is importing the default from './BoardActions'.

Looking at the first file you are exporting the result of a function rather than the class itself.

export default alt.createActions(BoardActions);

Asaf David
  • 3,167
  • 2
  • 22
  • 38
  • 1
    His module already has a default export. (Admittedly it was only added in an edit) – Bergi Mar 16 '16 at 13:35
  • Thanks. Edited my answer accordingly – Asaf David Mar 16 '16 at 13:41
  • Thanks. export default alt.createActions(BoardActions); makes all functions basically static. I just removed static from the function and it worked. – zeiteisen Mar 16 '16 at 14:11
  • @zeiteisen: "makes all functions basically static"??? That sounds like it instantiates the class to make a singleton from it. You really should not do that. Rather, just remove that call to `createActions`! – Bergi Mar 16 '16 at 20:36