Mixin: ResourceComponentMixin

ResourceComponentMixin

Resource Component Mixin

This mixin is used to help lighten the load of creating new Resource Components.
This mixin will handle adding and removing change listeneres, handling changes,
binding resources to scope, retrieving from stores, and firing optional callbacks as well.

Source:

Example

var ResourceComponentMixin = Mortar.Mixins.ResourceComponentMixin;
React.createClass({
	mixins: [ResourceComponentMixin],
	pageConfig: function() {
		stores: [
			store: UsersStore,
			action: UsersStore.getUsers, // makes this request when a change happens on UsersStore
			bindTo: 'users', // will do this.setState({users: UsersStore.getUsers})
			callback: this.myCallback // fired after state is set
		]
	},
	componentDidMount: function() {
		_componentDidMount();
	},
	componentWillUnmount: function() {
		_componentWillUnmount();
	}

Methods


<private, static> _componentDidMount()

_componentDidMount
Private function to not interfere with the componentDidMount of the user
Attaches change listeners to the stores in pageConfig

Source:

<private, static> _componentWillUnmount()

_componentWillUnmount
Private function to not interfere with the componentWillUnmount of the user
Removes change listeners to the stores in pageConfig

Source:

<private, static> _onChange()

_onChange
If the user doesn't pass a changeListener to the pageConfig, this one will be used be default
Reacts to changes in the store and re-requests the data, binding the updates to the component's state.

Source:
Returns:

Sets the state of the component calling this mixin

Type
function