Files
freeCodeCamp/common/app/flux/Actions.js

66 lines
1.3 KiB
JavaScript
Raw Normal View History

import { Actions } from 'thundercats';
import { Observable } from 'rx';
export default Actions({
2015-12-22 19:33:25 -08:00
shouldBindMethods: true,
refs: { displayName: 'AppActions' },
setTitle(title = 'Learn To Code') {
2015-12-22 19:33:25 -08:00
return { title: title + ' | Free Code Camp' };
},
getUser() {
2015-12-22 19:33:25 -08:00
return this.readService$('user', null, null)
.map(({
2015-12-22 19:33:25 -08:00
username,
picture,
progressTimestamps = [],
isFrontEndCert,
isBackEndCert,
2015-12-22 19:33:25 -08:00
isFullStackCert
}) => {
2015-12-22 19:33:25 -08:00
return {
username,
picture,
points: progressTimestamps.length,
isFrontEndCert,
isBackEndCert,
2015-12-22 19:33:25 -08:00
isFullStackCert
};
})
.catch(err => Observable.just({ err }));
},
2015-12-31 17:39:29 -08:00
// routing
2016-01-07 14:51:41 -08:00
// goTo(path: String) => path
2015-12-31 17:39:29 -08:00
goTo: null,
2016-01-07 14:51:41 -08:00
// goBack(arg?) => arg?
2015-12-31 17:39:29 -08:00
goBack: null,
2016-01-07 14:51:41 -08:00
// toast(args: { type?: String, message: String, title: String }) => args
toast(args) {
return {
transform(state) {
2016-01-09 22:49:16 -08:00
return {
...state,
toast: {
...args,
id: state.toast && state.toast.id ? state.toast.id : 1
}
};
2016-01-07 14:51:41 -08:00
}
};
},
// updateLocation(location: { pathname: String }) => location
2015-12-31 17:39:29 -08:00
updateLocation(location) {
return {
transform(state) {
return { ...state, location };
}
};
}
2015-12-22 19:33:25 -08:00
});