repertoire
  • Repertoire.js
  • Using Repertoire
  • API Reference
    • Controller
    • dispatchActions
  • Help
  • Changelog
Powered by GitBook
On this page
  • Properties
  • get stateNamespace()
  • get state()
  • set state(definition)
  • Methods
  • connect()
  • directConnect(componentName)
  1. API Reference

Controller

Properties

get stateNamespace()

Defines the namespace on the Redux store for the Controller. Multiple controllers can share the same namespace.

import {BaseController} from 'repertoire'

export default class AdminController extends BaseController {
  // the section of the redux store which this controller will operate on
  get stateNamespace() {
    return 'admin';
  }
}

get state()

Getter which can be used the retrieve the current Redux store state inside an action, conveniently as this.state

import {BaseController} from 'repertoire'

export default class MyController extends BaseController {
  incrementCounter() {
    return {
      counter: this.state.counter + 1
    }
  }
}

set state(definition)

Setter which defines the Redux store state which will be mapped to the React component.

import {BaseController} from 'repertoire'

export default class MyController extends BaseController {
  constructor(component) {
    super(component);
    
    this.state = {
      counter(store) {
        return store.counter || 0;
      }
    };
    
    this.connect();
  }
}

Methods

connect()

The resulting reducers and middleware watchers won't be added to the global reducer until the component is appended to the root component, usually as a Route using the React-Router.

directConnect(componentName)

This is the same as .connect() but the resulting reducers and middleware watchers will be added immediately to the global reducer.

import AppController from './controller.js'

class App extends React.Component {
  render() {
    return <div />;
  }
}

export default new AppController(App).directConnect('App');
PreviousAPI ReferenceNextdispatchActions

Last updated 6 years ago

This performs a call to the utility from react-redux given the currently defined actions and store state from the controller.

connect()