Files
freeCodeCamp/common/app/Cat.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

import { Cat } from 'thundercats';
2015-12-22 19:32:12 -08:00
import stamp from 'stampit';
import { Disposable, Observable } from 'rx';
2015-07-25 15:15:59 -07:00
2015-12-29 17:35:50 -08:00
import { post$, postJSON$ } from '../utils/ajax-stream.js';
import { AppActions, AppStore } from './flux';
2015-12-22 19:32:12 -08:00
import { HikesActions } from './routes/Hikes/flux';
2015-07-25 15:15:59 -07:00
import { JobActions, JobsStore} from './routes/Jobs/flux';
2015-12-26 00:42:39 -08:00
const ajaxStamp = stamp({
methods: {
2015-12-29 17:35:50 -08:00
postJSON$,
post$
2015-12-26 00:42:39 -08:00
}
});
2015-12-22 19:32:12 -08:00
export default Cat().init(({ instance: cat, args: [services] }) => {
const serviceStamp = stamp({
methods: {
readService$(resource, params, config) {
2015-07-25 15:15:59 -07:00
2015-12-22 19:32:12 -08:00
return Observable.create(function(observer) {
services.read(resource, params, config, (err, res) => {
if (err) {
observer.onError(err);
return observer.onCompleted();
}
2015-07-25 15:15:59 -07:00
2015-12-22 19:32:12 -08:00
observer.onNext(res);
observer.onCompleted();
});
return Disposable.create(function() {
observer.onCompleted();
});
});
}
}
});
2015-12-22 19:32:12 -08:00
2015-12-26 00:42:39 -08:00
cat.register(HikesActions.compose(serviceStamp, ajaxStamp), null, services);
2015-12-22 19:32:12 -08:00
cat.register(AppActions.compose(serviceStamp), null, services);
cat.register(AppStore, null, cat);
cat.register(JobActions, null, cat, services);
cat.register(JobsStore.compose(serviceStamp), null, cat);
});