1

这是具有静态功能的类

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);

这是调用静态函数的类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);

我收到此错误:

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

怎么了?

编辑:我使用 babel 作为转译器。

"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",
4

1 回答 1

1

已编辑(因为您编辑了问题):

在您要导入的第二个文件中

import BoardActions from './BoardActions';

这是从“./BoardActions”导入默认值。

查看第一个文件,您正在导出函数的结果而不是类本身。

export default alt.createActions(BoardActions);

于 2016-03-16T13:28:09.683 回答