Skip to content

Releases: epos-next/web

Pre-release 0.0.3

12 Aug 13:44
Compare
Choose a tag to compare
Pre-release 0.0.3 Pre-release
Pre-release

Pre-release 0.0.3

Cover all services with unit tests

The number of tests has increased to 82🤩

Test files

Refactor: improve reducers and split state access

11 Aug 13:08
Compare
Choose a tag to compare

0.0.2 here!

0.0.1 is inside @zotovy private repository, so, it's 0.0.2

Based on #1

Rewrote reducers using redux-toolkit for a more modern and convenient work with redux. Move access to redux store (useSelector and useDispatch) to as lower components (like leaves of component tree) as it's possible to improve re-render performance. Cover reducers with unit tests

New reducers

The basic example of reducer looks like this

export default (state: State = initialState, action: AnyAction) => {
    if (setUser.match(action)) {
        return {
            ...state,
            user: action.payload,
        }
    }
    return state;
}

This way of creating reducers requires actions & action creators to be defined by hand. Also, this is quite inconvenient to write all this 100 if's blocks.

Now reducers and action, and action creators defines by createSlice method.

export const userSlice = createSlice({
    name: "user",
    initialState,
    reducers: {
        setUser: (state, action: PayloadAction<User | null>) => {
            state.user = action.payload;
        }
    }
});

Every reducer file export named actions, selectors and reducer itself

export const { setUser } = userSlice.actions;

export const selectUser = (state: RootState) => state.userState.user;
export const selectUserLoading = (state: RootState) => state.userState.user === null;

const userReducer = userSlice.reducer;
export default userReducer;

Every layout can access redux store

Epos was initially designed to access state only from root component (page). But's that's terrible for the performance because every time smth change, the whole app re-render (not actually re-render, react is smart guy, but it still significantly reduces performance)

Now every layout can access redux store and in the future be sure to follow this

Unit test are here

Setup jest and cover all the reducers with tests. In the future, have to cover at least 80% of code with unit testing.
The next goal to testing will be services, because that's where all business logic happened