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

buffers.ts (1473B)


      1 export type BufferState = { [key: string]: WeechatBuffer };
      2 
      3 const initialState: BufferState = {};
      4 
      5 export default (state: BufferState = initialState, action): BufferState => {
      6   switch (action.type) {
      7     case "FETCH_BUFFERS": {
      8       return action.payload;
      9     }
     10     case "BUFFER_CLOSED": {
     11       return Object.fromEntries(Object.entries(state)
     12         .filter(([bufferId]) => bufferId !== action.bufferId));
     13     }
     14     case "BUFFER_OPENED": {
     15       return {
     16         ...state,
     17         [action.bufferId]: action.payload
     18       };
     19     }
     20     case "BUFFER_LOCALVAR_UPDATE": {
     21       return {
     22         ...state,
     23         [action.bufferId]: {
     24           ...state[action.bufferId],
     25           local_variables: {
     26             ...state[action.bufferId].local_variables,
     27             ...action.payload.local_variables
     28           }
     29         }
     30       };
     31     }
     32     case "BUFFER_LOCALVAR_REMOVE": {
     33       if (state[action.bufferId]) {
     34         return {
     35           ...state,
     36           [action.bufferId]: {
     37             ...state[action.bufferId],
     38             local_variables: {
     39               ...action.payload.local_variables
     40             }
     41           }
     42         };
     43       } else {
     44         return state;
     45       }
     46     }
     47     case "BUFFER_RENAMED": {
     48       return {
     49         ...state,
     50         [action.bufferId]: {
     51           ...state[action.bufferId],
     52           full_name: action.payload.full_name,
     53           short_name: action.payload.short_name
     54         }
     55       };
     56     }
     57     default:
     58       return state;
     59   }
     60 };