Skip to content

Instantly share code, notes, and snippets.

@FelipeBarrosCruz
Forked from klaygomes/test.js
Last active April 28, 2016 00:39
Show Gist options
  • Select an option

  • Save FelipeBarrosCruz/ab6ce7d9282930bce119df9b65cdad28 to your computer and use it in GitHub Desktop.

Select an option

Save FelipeBarrosCruz/ab6ce7d9282930bce119df9b65cdad28 to your computer and use it in GitHub Desktop.
'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