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
{ | |
"items": [ | |
{ | |
"id": "item-id-1", | |
"type": "username", | |
"placeholder": "Please enter your username", | |
"required:": true, | |
"minLength": 3, | |
"maxLength": 15 | |
}, |
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
function Factory(item) { | |
switch (item.type) { | |
case 'username': | |
return <Username item={item} />; | |
case 'password': | |
return <Password item={item} />; | |
case 'birthday': | |
return <Birthday item={item} />; | |
case 'gender': | |
return <Gender item={item} />; |
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
render() { | |
const { items } = this.props; | |
const components = items.map(item => <Factory item={item} />); | |
return ( | |
<View> | |
{components} | |
</View> | |
); |
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
function Factory(item) { | |
switch (item.type) { | |
case 'username': | |
return <Username item={item} />; | |
case 'password': | |
return <Password item={item} />; | |
case 'birthday': | |
return <Birthday item={item} />; | |
case 'gender': | |
return <Gender item={item} />; |
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
class Field extends Component { | |
constructor({ type }) { | |
super(); | |
this.type = type; | |
} | |
} | |
export default Field; |
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
class Username extends Field { | |
const { item } = this.props; | |
render() { | |
... | |
} | |
} | |
class UsernameFactory { | |
get type() { return 'username'; } |
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
class Password extends Field { | |
const { item } = this.props; | |
render() { | |
... | |
} | |
} | |
class PasswordFactory { | |
get type() { return 'password'; } |
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
class Birthday extends Field { | |
const { item } = this.props; | |
render() { | |
... | |
} | |
} | |
class BirthdayFactory { | |
get type() { return 'birthday'; } |
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
class Gender extends Field { | |
const { item } = this.props; | |
render() { | |
... | |
} | |
} | |
class GenderFactory { | |
get type() { return 'gender'; } |
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
class Factory { | |
constructor() { | |
this.factoryMapper = new FactoryMapper(); | |
} | |
create({ item }) { | |
const { type } = item; | |
const factory = this.factoryMapper.factory(type); | |
return factory.create({ item }); | |
} |
OlderNewer