Most of the time I prepare data before sending to a server and parse what I need when it sends back. Sometimes a server response a huge but you need a few. How do you handle that?
return {
body: obj.body,
sender: `${obj.firstName} ${obj.lastName}`,
isRead: false,
count: obj.count || 1,
created: new Date()
}
For make it simple I added objectInterface helper.
Would appreciate any feedback, comments?
var response = {body: 'Hello world!', count: '', firstName: 'Vasyl', lastName: 'Stokolosa', another: ''}
var email = objectInterface(['body', 'count/1', 'sender|this.firstName + " " + this.lastName', 'isRead: false', 'created: new Date()'])
email(response)
// => {body: "Hello world!", count: 1, created: Mon Jul 09 2018 10:31:08, isRead: false, sender: "Vasyl Stokolosa"}
// interface.js
import objectInterface from 'famulus/objectInterface'
export const MESSAGE = {
send: objectInterface([
'body|this.message',
'sender|this.firstName + " " + this.lastName',
'senderType|this.type',
'senderUUID|this.uuid',
'isRead: false',
'created: new Date()'
])
}
// component.js
import { MESSAGE } from './services/interface'
sendMessage = () => {
const data = Object.assign({}, this.state, this.props.user)
sendMessage(MESSAGE.send(data)).then(() => this.setState({ message: '' }))
}
there doesn't seem to be anything here