Last active
October 16, 2019 18:19
-
-
Save mattmccray/9f88cd9003721af6cb9e3c2adcf3c222 to your computer and use it in GitHub Desktop.
Example "Smart Component"
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 React from 'react' | |
import { UIController, useController } from '../core' | |
import { stylesheet } from '../theme' | |
import { DomainObjectList } from 'fp-api' | |
type EmailAddressListProps = { | |
customerId: number | |
} | |
class EmailAddressListController extends UIController<EmailAddressListProps> { | |
emails: DomainObjectList<CustomerEmailAddress> | |
async initialize() { | |
const { customerId } = this.params | |
const { rest } = this.services | |
this.emails = await rest.fetchList<CustomerEmailAddress>("CustomerEmailAddress", { customerId }) | |
} | |
} | |
export const EmailAddressList = (props: EmailAddressListProps) => { | |
const ctrl = useController(EmailAddressListController, props) | |
return ctrl.render(() => ( | |
<div className={CSS.EmailAddressList}> | |
{ctrl.emails.map(email => (<EmailListItem email={email} key={email.emailAddressId} />))} | |
</div> | |
)) | |
} | |
export default EmailAddressList | |
const CSS = stylesheet({ | |
EmailAddressList: {}, | |
}) |
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
/** | |
We could have different form factor views in the same Smart Component, if/when it makes sense. | |
*/ | |
import React from 'react' | |
import { UIController, useController } from '../core' | |
import { stylesheet } from '../theme' | |
import { DomainObjectList } from 'fp-api' | |
type EmailAddressListProps = { | |
customerId: number | |
} | |
class EmailAddressListController extends UIController<EmailAddressListProps> { | |
emails: DomainObjectList<CustomerEmailAddress> | |
async initialize() { | |
const { customerId } = this.params | |
const { rest } = this.services | |
this.emails = await rest.fetchList<CustomerEmailAddress>("CustomerEmailAddress", { customerId }) | |
} | |
} | |
export const EmailAddressList = (props: EmailAddressListProps) => { | |
const ctrl = useController(EmailAddressListController, props) | |
return ctrl.render(() => ( | |
<div className={CSS.EmailAddressList}> | |
{ctrl.emails.map(email => (<EmailListItem email={email} key={email.emailAddressId} />))} | |
</div> | |
)) | |
} | |
export const EmailAddressListMobile = (props: EmailAddressListProps) => { | |
const ctrl = useController(EmailAddressListController, props) | |
return ctrl.render(() => ( | |
<ion-list className={CSS.EmailAddressListMobile}> | |
{ctrl.emails.map(email => (<EmailListItemMobile email={email} key={email.emailAddressId} />))} | |
</ion-list> | |
)) | |
} | |
export default EmailAddressList | |
const CSS = stylesheet({ | |
EmailAddressList: {}, | |
EmailAddressListMobile: {}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment