horizon
horizon copied to clipboard
collection.store(object) mutates date values
Server version: 1.1.3 Client version: 1.1.3
I'm using ng2 and piping a date object into a particular format within my view. Upon using store, the date is replaced by Horizon/RethinkDB metadata within the original object so my view dies. I'm currently getting around this by copying the object with: Object.assign({}, o)
Example:
var o = {
name: 'test',
created: new Date()
};
horizon('things').store(o).subscribe(() => {
console.log(o.created); // {$reql_type$: "TIME", epoch_time: 1465318800, timezone: 'Z' }
});
Shoot! Deserialize should definitely not mutate, that was a bad call on my part (trying to be prematurely efficient :/)
How do we work around this? Is there an easy way to convert this object to a regular Date object? Like, maybe, new Date(o.created.epoch_time)
? Or do you suggest that we don't store Date objects, but instead store timestamps, date.getTime()
?
Maybe copy the object before storing it, and copy the returned id back to the original copy? Hairy...
The same problem occurs with collection.update
.