Skip to content

Instantly share code, notes, and snippets.

@oziks
Created August 23, 2017 13:58
Show Gist options
  • Save oziks/d83d599fffc83615b3ad3c023b42b9be to your computer and use it in GitHub Desktop.
Save oziks/d83d599fffc83615b3ad3c023b42b9be to your computer and use it in GitHub Desktop.
BetaSeries api redux sdk runner
// use babel-register to precompile ES6 syntax
require('babel-register')({
ignore: /node_modules/,
});
require('isomorphic-fetch');
require('./test');
import { createStore, applyMiddleware, combineReducers, compose } from 'redux';
import thunkMiddleware from 'redux-thunk';
import BetaSeries from '../lib/betaseries';
const debug = require('debug')('sdk');
BetaSeries.init({ apiKey: '1', 'apiHost': 'http://dev.api.betaseries.com'});
BetaSeries.logger = ({ method, url, qs, header, ...props }) => {
debug(`${method} ${url}`);
debug('%o', props.querystring);
debug('%o', header);
};
BetaSeries.setUser({
token: 'f20765f42659',
userId: 4,
});
const store = createStore(
combineReducers({
...BetaSeries.getReducer('movies', 'favorites'),
...BetaSeries.getReducer('movies', 'characters'),
...BetaSeries.getReducer('movies', 'members'),
...BetaSeries.getReducer('movies', 'movies'),
...BetaSeries.getReducer('shows', 'shows'),
...BetaSeries.getReducer('shows', 'characters'),
...BetaSeries.getReducer('shows', 'episodes'),
...BetaSeries.getReducer('shows', 'similars'),
...BetaSeries.getReducer('shows', 'membersEpisodesToSee'),
...BetaSeries.getReducer('shows', 'discover'),
...BetaSeries.getReducer('shows', 'members'),
...BetaSeries.getReducer('shows', 'episodesSubtitles'),
...BetaSeries.getReducer('comments', 'comments'),
...BetaSeries.getReducer('comments', 'episodes'),
...BetaSeries.getReducer('comments', 'shows'),
...BetaSeries.getReducer('comments', 'events'),
...BetaSeries.getReducer('members', 'members'),
...BetaSeries.getReducer('planning', 'timeline'),
...BetaSeries.getReducer('timelines', 'events'),
...BetaSeries.getReducer('timelines', 'friends'),
...BetaSeries.getReducer('timelines', 'feed'),
...BetaSeries.getReducer('timelines', 'members'),
...BetaSeries.getReducer('timelines', 'shows'),
...BetaSeries.getReducer('badges', 'badges'),
...BetaSeries.getReducer('polls', 'polls'),
...BetaSeries.getReducer('searchs', 'all'),
}),
compose(
applyMiddleware(
thunkMiddleware
)
),
);
store.dispatch(BetaSeries.getAction('shows', 'doFetchEpisodeSubtitles')({
episodeId: 20,
}))
.then((response) => {
console.log(response);
console.log(BetaSeries.getSelector('shows', 'getEpisodeSubtitles')(store.getState(), {
episodeId: response.payload.episodeId,
}));
console.log(store.getState());
})
.catch(error => {
console.log({ error });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment