Skip to content

Proposal for app styles #2

@hobbes7878

Description

@hobbes7878

Proposal 1

Use CSS modules and colocate SCSS and component files.

card/
  Card.jsx
  card.scss
// Card.jsx
import React from 'react';
import classNames from 'classnames/bind';
import styles from './card.scss';

const cx = classNames.bind(styles);

const Card = props =>
  <div classNames=cx('card', { active: props.active }) />

Proposal 2

Colocate selectors with reducers.

import * as actions from './constants';

// Export reducer as default export
export default (currentState, action) => {
  const initialState = {
    races: {},
  };
  // ...
  return newState;
}

// Export selectors as named exports
export const getActiveRaces = state =>
  state.races.filter(r => r.active);

Selectors should operate on the same state as is defined in the reducer.

Prune the state in another place, if the reducer state is only a piece of the app's store.

import races, * as fromRaces from './races';

export default combineReducers({
  // ...
  races,
});

export const getActiveRaces = (state) =>
  fromRaces.getActiveRaces(state.races);

Proposal 3

Separate files structure by domain instead of by function.

Separated by function.

actions/
  api/
    races.js
  cards.js
  index.js
  nav.js
components/
  Card.jsx
  Nav.jsx
constants/
  actions.js
containers/
  CardWell.jsx
  NavWell.jsx
reducers/
  cards.js
  index.js
  nav.js
stores/
  index.js
App.jsx

Separated by domain.


card/
  actions.js
  Card.jsx
  constants.js
  reducer.js
  Well.jsx
nav/
  actions.js
  constants.js
  Nav.jsx
  reducer.js
  Well.jsx
races/
  actions.js
  api.js
  constants.js
  reducer.js
stores/
  index.js
App.jsx

Proposal 4

Each directory should define all exports in a single file, index.js and all other modules should only consume the exports defined in that file.

card/
  actions.js
  Card.jsx
  constants.js
  index.js
  reducer.js
  Well.jsx
// index.js
export * as actions from './actions';
export * as constants from './constants';
export default as Card from './Card';
// some-other.js
// NOT THIS
import * as cardConstants from '../card/constants';
import * as cardActions from '../card/actions';
import Card from '../card/Card';
// THIS
import { constants as cardConstants, actions as cardActions, Card } from '../card';

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions