Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamline redux structure #7910

Closed
charrondev opened this issue Oct 10, 2018 · 0 comments
Closed

Streamline redux structure #7910

charrondev opened this issue Oct 10, 2018 · 0 comments
Assignees
Milestone

Comments

@charrondev
Copy link
Contributor

While bringup @initvector up on frontends project structure it became apparent that things were spread over too many files. This new structure was introduced in https://github.com/vanilla/knowledge/pull/163#structure.

Overview

This is what the state structure looks like now:

modules/editor/state

  • constants.ts - Constant values for the module. This currently has action types and route paths.
  • actions.ts - These are the simple action creators. Everything here is synchronous, "plain" redux. Eg. a function that takes some props and directly returns an action object. This also exports all of the action types for reducers.
  • model.ts - This contains the interface for the modules local state. For more complicated modules in the future it may contain selectors for selecting, or manipulating parts of this state.
  • reducer.ts - This contains the reducer function that handles the actions and returns the updated state tree.
  • thunks.ts - These are async actions. See redux-thunk. Basically the function here can make async events and dispatch other actions or other thunks. This is where side affects like network requests, IO, or updating navigation programatically should take place.
  • index.ts - This is the barrel file. It re-exports the relevant bits for external consumption. No files outside of this state directory should import any of them directly. Instead they should be imported from the barrel. Eg. import {constants} from "modules/editor/state" instead of import * as constants from "modules/editor/state/constants".

Changes

I'm looking to streamline this by doing the following:

  • Add 2 new base classes. ReduxReducer and ReduxActions. Each new state structure will extend these.
  • ReduxActions will contain most of @library/state/utility as protected methods for it's subclasses to use.

Re-arranging

The previous file contents will be moved as follows:

  • constants.ts - Static constants on the Actions class.
  • actions.ts - Private static methods on the Actions class.
  • model.ts - Public static methods on the Reducer class.
  • reducer.ts - Public instance methods on the Reducer class.
  • thunks.ts - Public instance methods on the Actions class.
  • index.ts - Removed. No longer necessary.

Old utility methods

The old utility methods will be marked as deprecated and moved shortly after the initial implementation. The current call sites here that will need to be updated are the rich-editor's couple reducers, which already needed an update, and the authenticate page's reducer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants