This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let isValid = (data) => {...} | |
let submitEntityForm = (data) => { | |
if (!isValid(data)) { | |
// add error notification... | |
}; | |
dispatch('SUBMIT_ENTITY_FORM', data); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let submitEntityForm = (data) => { | |
dispatch('SUBMIT_ENTITY_FORM', data); | |
} | |
let MyFormComponent = () => { | |
return { | |
<Form> | |
<Button type={'submit'} onClick={submitEntityForm}/> | |
</Form> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UCM React Basic Example | |
IDLE | |
input -> ACTIVE | |
ACTIVE | |
submit -> WAITING | |
blur -> IDLE | |
WAITING | |
invalid -> FORM_INVALID | |
resolve -> SUCCESS | |
reject -> HAS_ERROR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('when editing an entity', () => { | |
it('posts the entity form and does all the right stuff afterward', () => { | |
stub(myModule, 'prePopulateForm'); | |
dispatch = jest.fn(); | |
postEntityForm(); | |
expect(dispatch).toHaveBeenCalledTimes(6); | |
expect(prePopulateForm).toHaveBeenCalledTimes(1) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is oversimplified. The real code for this callback would be a complicated graph | |
// of nested asynchronous and synchronous calls. Imagine at the edge of thes thunks each | |
// dispatched action mutates state. | |
let postEntityForm = (e, data) => { | |
await dispatch(saveEntity(data)); | |
let entities = await dispatch(fetchEntities()); | |
let taxPolicy = await dispatch(maybeFetchEntityTaxPolicy()); | |
await dispatch(maybeUpdateEntityPriceSuggestions(taxPolicy, entities)); | |
let isEditing = dispatch(getIsEditingFromState()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
handleCampaignClick = (campaign, actionName) => { | |
if (actionName === 'activate') { | |
const campaigns = this.props.campaigns; | |
const hasNoActivated = !campaigns.some(c => c.activated); | |
if (hasNoActivated) { | |
updateCampaignAndUpdateFeaturedCampaigns({ | |
id: campaign.id, | |
activated: true | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
handleCampaignClick = (campaign, actionName) => { | |
if (actionName === 'activate') { | |
const campaigns = this.props.campaigns; | |
const hasNoActivated = !campaigns.some(c => c.activated); | |
if (hasNoActivated) { | |
updateCampaign({ | |
id: campaign.id, | |
value: true | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
handleCampaignClick = (campaign, actionName) => { | |
if (actionName === 'activate') { | |
updateCampaign({ | |
id: campaign.id, | |
value: true, | |
}); | |
} | |
if (actionName === 'makeFeatured') { | |
updateFeaturedCampaigns({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const saveStuffThunk = async (formData) => { | |
async(dispatch, getState) => { | |
try { | |
await saveParentEntity(getParentEntityFromForm(formData)); | |
} catch (e) { | |
throw SubmissionError(e); | |
} | |
try { | |
await saveChildEntity(getChildEntityFromForm(formData)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import InventoryManagementView from '../components/InventoryManagementView' | |
import {eventIsSellable} from '../selectors/event'; | |
const userCanSellEvent = eventIsSellable(this.props.event); | |
if (userCanSellEvent) { | |
return InventoryManagementView; | |
} |