-
-
Save FelipeBarrosCruz/ab6ce7d9282930bce119df9b65cdad28 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
| 'use strict'; | |
| var Schema = { | |
| name: { | |
| type: String | |
| }, | |
| lastname: { | |
| type: String | |
| }, | |
| avatar: { | |
| type: Number | |
| }, | |
| birthday: { | |
| type: Date | |
| } | |
| }; | |
| /* Implementação especializada */ | |
| var doAction = (() => { | |
| function doActionInName(name, cb) { | |
| var err = null; | |
| try { | |
| var value = '[[ '.concat(name).concat(' ]]'); | |
| /* DO SOMETHING ELSE HERE */ | |
| } catch(e) { | |
| err = e; | |
| } | |
| return cb(err, value); | |
| } | |
| function doActionInBirthDay(birthday, cb) { | |
| var err = null; | |
| try { | |
| var value = moment(birthday).format('YYYY-MM-DD hh:mm:ss'); | |
| /* DO SOMETHING ELSE HERE */ | |
| } catch(e) { | |
| err = e; | |
| } | |
| return cb(err, value); | |
| } | |
| function defaultAction(value) { | |
| return value; | |
| } | |
| return { | |
| doActionInName: doActionInName, | |
| doActionInBirthDay: doActionInBirthDay, | |
| defaultAction: defaultAction | |
| }; | |
| })(); | |
| /* código de intra-estrutura code */ | |
| function Action(field) { | |
| var List = { | |
| name: doAction.doActionInName || doAction.defaultAction, | |
| birthday: doAction.doActionInBirthDay || doAction.defaultAction | |
| }; | |
| return (List[field]) | |
| ? List[field] | |
| : (data, cb) => { | |
| return cb(null, data); | |
| }; | |
| } | |
| /* código do cliente */ | |
| Action('name')('Felipe Barros', (err, value) => { | |
| if (err) { | |
| return console.log('Some error happend', err); | |
| } | |
| return console.log('A new value: ', value); | |
| }); | |
| Action('birthday')(new Date(1993, 9, 8), (err, value) => { | |
| if (err) { | |
| return console.log('Some error happend', err); | |
| } | |
| return console.log('A new value: ', value); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment