mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-27 19:42:11 +10:00
Inject the SDK instance to the root saga
This commit is contained in:
parent
f17a5ec36b
commit
bbddb7ae27
2 changed files with 15 additions and 40 deletions
13
src/index.js
13
src/index.js
|
|
@ -13,10 +13,12 @@
|
|||
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { createInstance, types } from 'sharetribe-sdk';
|
||||
import { ClientApp, renderApp } from './app';
|
||||
import configureStore from './store';
|
||||
import { matchPathname } from './util/routes';
|
||||
import rootSaga from './sagas';
|
||||
import createRootSaga from './sagas';
|
||||
import config from './config';
|
||||
|
||||
import './index.css';
|
||||
|
||||
|
|
@ -25,9 +27,16 @@ if (typeof window !== 'undefined') {
|
|||
// eslint-disable-next-line no-underscore-dangle
|
||||
const preloadedState = window.__PRELOADED_STATE__ || {};
|
||||
const store = configureStore(preloadedState);
|
||||
store.runSaga(rootSaga);
|
||||
const sdk = createInstance({ clientId: config.sdk.clientId, baseUrl: config.sdk.baseUrl });
|
||||
|
||||
store.runSaga(createRootSaga(sdk));
|
||||
|
||||
ReactDOM.render(<ClientApp store={store} />, document.getElementById('root'));
|
||||
|
||||
// Expose stuff for the browser REPL
|
||||
if (config.dev) {
|
||||
window.app = { config, sdk, sdkTypes: types };
|
||||
}
|
||||
}
|
||||
|
||||
// Export the function for server side rendering.
|
||||
|
|
|
|||
42
src/sagas.js
42
src/sagas.js
|
|
@ -1,42 +1,8 @@
|
|||
import { createInstance } from 'sharetribe-sdk';
|
||||
|
||||
import { watchAuth } from './ducks/Auth.duck';
|
||||
import { watchLoadListings } from './containers/SearchPage/SearchPage.duck';
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
import fakeSdk from './util/fakeSDK';
|
||||
|
||||
const clientId = '08ec69f6-d37e-414d-83eb-324e94afddf0';
|
||||
const baseUrl = 'http://localhost:8088';
|
||||
const createRootSaga = sdk => function* rootSaga() {
|
||||
yield [watchAuth(sdk), watchLoadListings(sdk)];
|
||||
};
|
||||
|
||||
const sdk = createInstance({ clientId, baseUrl });
|
||||
|
||||
const mockLogin = (email, password) => new Promise((resolve, reject) => {
|
||||
window.setTimeout(
|
||||
() => {
|
||||
if (email && password) {
|
||||
// any non-empty email and password is ok
|
||||
resolve({ email, password });
|
||||
} else {
|
||||
reject(new Error('Invalid credentials, try a valid email and a non-empty password'));
|
||||
}
|
||||
},
|
||||
1000,
|
||||
);
|
||||
});
|
||||
|
||||
const mockLogout = () => new Promise(resolve => {
|
||||
window.setTimeout(resolve, 1000);
|
||||
});
|
||||
|
||||
// Temporary mock SDK
|
||||
const mockSdk = { login: mockLogin, logout: mockLogout };
|
||||
|
||||
export default function* rootSaga() {
|
||||
// TODO: inject sdk in function arguments
|
||||
|
||||
// FakeSDK
|
||||
// yield [watchAuth(mockSdk), watchLoadListings(fakeSdk)];
|
||||
|
||||
// Real SDK
|
||||
yield [watchAuth(mockSdk), watchLoadListings(sdk)];
|
||||
}
|
||||
export default createRootSaga;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue