Files
freeCodeCamp/common/app/Cat.js

66 lines
1.7 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';
2016-01-06 09:33:55 -08:00
import HikesActions from './routes/Hikes/flux';
import JobActions 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) {
2016-01-04 14:26:07 -08:00
return observer.onError(err);
2015-12-22 19:32:12 -08:00
}
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() {
2016-01-04 14:26:07 -08:00
observer.dispose();
});
});
},
createService$(resource, params, body, config) {
return Observable.create(function(observer) {
services.create(resource, params, body, config, (err, res) => {
if (err) {
return observer.onError(err);
}
observer.onNext(res);
2015-12-22 19:32:12 -08:00
observer.onCompleted();
});
2016-01-04 14:26:07 -08:00
return Disposable.create(function() {
observer.dispose();
});
2015-12-22 19:32:12 -08:00
});
}
}
});
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);
2016-01-04 14:26:07 -08:00
cat.register(
JobActions.compose(serviceStamp, ajaxStamp),
null,
cat,
services
);
2015-12-22 19:32:12 -08:00
cat.register(AppStore, null, cat);
});