weechatRN

Weechat relay client for iOS using websockets https://github.com/mhoran/weechatRN
git clone http://git.hanabi.in/repos/weechatRN.git
Log | Files | Refs | README | LICENSE

index.ts (1675B)


      1 import { combineReducers, createStore, applyMiddleware } from 'redux';
      2 import { composeWithDevTools } from 'redux-devtools-extension';
      3 import thunk from 'redux-thunk';
      4 import { persistStore, persistReducer } from 'redux-persist';
      5 import AsyncStorage from '@react-native-async-storage/async-storage';
      6 
      7 import buffers, { BufferState } from './buffers';
      8 import lines, { LineState } from './lines';
      9 import hotlists, { HotListState } from './hotlists';
     10 import connection, { ConnectionInfo } from './connection-info';
     11 import nicklists, { NicklistState } from './nicklists';
     12 
     13 type AppState = {
     14   connected: boolean;
     15   currentBufferId: string | null;
     16 };
     17 
     18 export type StoreState = {
     19   app: AppState;
     20   connection: ConnectionInfo;
     21   buffers: BufferState;
     22   lines: LineState;
     23   hotlists: HotListState;
     24   nicklists: NicklistState;
     25 };
     26 
     27 const initialState: AppState = {
     28   connected: false,
     29   currentBufferId: null
     30 };
     31 
     32 const app = (state: AppState = initialState, action) => {
     33   switch (action.type) {
     34     case 'DISCONNECT':
     35       return {
     36         ...state,
     37         connected: false
     38       };
     39     case 'FETCH_VERSION':
     40       return {
     41         ...state,
     42         connected: true
     43       };
     44     case 'CHANGE_CURRENT_BUFFER':
     45       return {
     46         ...state,
     47         currentBufferId: action.bufferId
     48       };
     49     default:
     50       return state;
     51   }
     52 };
     53 
     54 export const reducer = combineReducers({
     55   app,
     56   buffers,
     57   lines,
     58   connection,
     59   hotlists,
     60   nicklists
     61 });
     62 
     63 export const store = createStore(
     64   persistReducer(
     65     { storage: AsyncStorage, key: 'state', whitelist: ['connection'] },
     66     reducer
     67   ),
     68   composeWithDevTools(applyMiddleware(thunk))
     69 );
     70 
     71 export const persistor = persistStore(store);