Created
September 1, 2017 15:56
-
-
Save Leko/a2cb634b20ca153862f2056557b04246 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Avatar { | |
constructor (uri) { | |
this.setUri(uri) | |
Object.freeze(this) | |
} | |
setUri (uri) { | |
this.uri = uri | |
} | |
} | |
class Name { | |
constructor (firstName, lastName) { | |
this.setFirstName(firstName) | |
this.setLastName(lastName) | |
Object.freeze(this) | |
} | |
setFirstName (firstName) { | |
this.firstName = firstName | |
} | |
setLastName (lastName) { | |
this.lastName = lastName | |
} | |
} | |
class Age { | |
constructor (age) { | |
this.setAge(age) | |
Object.freeze(this) | |
} | |
setAge (age) { | |
this.age = age | |
} | |
} | |
class EmailAddress { | |
constructor (emailAddress) { | |
this.setEmailAddress(emailAddress) | |
Object.freeze(this) | |
} | |
setEmailAddress (emailAddress) { | |
this.emailAddress = emailAddress | |
} | |
} | |
class Biography { | |
constructor (biography) { | |
this.setBiography(biography) | |
Object.freeze(this) | |
} | |
setBiography (biography) { | |
this.biography = biography | |
} | |
} | |
class Profile { | |
constructor ({ avatar, name, age, email, biography }) { | |
this.avatar = avatar | |
this.name = name | |
this.age = age | |
this.email = email | |
this.biography = biography | |
} | |
} | |
class ProfileFactory { | |
static get defaults () { | |
return { | |
} | |
} | |
static fromObject ({ avatar, firstName, lastName, age, emailAddress, biography }) { | |
return new Profile(Object.assign(this.defaults, { | |
avatar: new Avatar(avatar), | |
name: new Name(firstName, lastName), | |
age: new Age(age), | |
emailAddress: new EmailAddress(emailAddress), | |
biography: new Biography(biography), | |
})) | |
} | |
} | |
class ProfileRepository { | |
} | |
class ProfileSpecification extends EntityValidatable { | |
static get SCHEMA () { | |
return { | |
type: 'object', | |
properties: {}, | |
required: [], | |
} | |
} | |
static isValid () { | |
} | |
static validate (profile) { | |
} | |
} | |
import { | |
ProfileForm, | |
AvatarInput, | |
NameInput, | |
AgeInput, | |
EmailAddressInput, | |
BiographyInput, | |
} from './components/models/Profile' | |
class EditProfile extends Component { | |
state = { | |
valid: false, | |
errors: [], | |
profile: null, | |
} | |
handleChangeValidityState = (validityState) => { | |
this.setState({ | |
valid: validityState.valid, | |
errors: toErrorMessage(validityState, ProfileSpecification.SCHEMA), | |
}) | |
} | |
handleChange = (profile) => { | |
this.setState({ profile }) | |
} | |
handleSubmit = () => { | |
this.props.actions.save(this.state.profile) | |
} | |
render () { | |
const { profile } = this.props | |
if (!profile) { | |
return null | |
} | |
return ( | |
<ProfileForm | |
onChangeValidityState={this.handleChangeValidityState} | |
onChange={this.handleChange} | |
onSubmit={this.handleSubmit} | |
> | |
<AvatarInput | |
model={profile} | |
errors={this.state.errors.avatar} | |
/> | |
<NameInput | |
model={profile} | |
errors={this.state.errors.name} | |
/> | |
<AgeInput | |
model={profile} | |
errors={this.state.errors.age} | |
/> | |
<EmailAddressInput | |
model={profile} | |
errors={this.state.errors.emailAddress} | |
/> | |
<BiographyInput | |
model={profile} | |
errors={this.state.errors.biography} | |
/> | |
<button type='submit'>送信</button> | |
</ProfileForm> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment