goatslacker / goatslacker/alt

Instance `addStore` / `addActions` breaks with real classes

Open
#604 5 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.4k
Forks
312
PR merge metrics
No merged PRs in 30d

Description

This works fine when babels transpiles with a `es2015` preset.

```
import Alt from 'alt';

class SessionStore {
constructor () {;
this.bindActions(this.alt.getActions('Session'));
}
onUpdateId (id) {
this.setState({
id
});
}
}

class SessionActions {
updateId (id) {
return dispatch => {
setTimeout(function () {
dispatch(id);
}, 1500);
};
}
}

class MyAlt extends Alt {
constructor (config = {}) {
super(config);
this.addActions('Session', SessionActions);
this.addStore('Session', SessionStore);
}
}

module.exports = MyAlt;

```

However, if the Node version it's running on already has native classes, it generates the following error:

```
TypeError: Class constructors cannot be invoked without 'new'
at ActionsGenerator.SessionActions (alt.js:15:1)
at new ActionsGenerator (/Users/leebenson/dev/project/web/node_modules/alt/lib/index.js:182:92)
at /Users/leebenson/dev/project/web/node_modules/alt/lib/index.js:205:30
at MyAlt.createActions (/Users/leebenson/dev/project/web/node_modules/alt/lib/index.js:206:11)
at MyAlt.addActions (/Users/leebenson/dev/project/web/node_modules/alt/lib/index.js:297:126)
at new MyAlt (alt.js:28:10)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.