Reputation: 2566
I have a server side collection to which I subscribe on the client side. The client does not have write access to the server side collection.
I would like to modify the collection on the client side only and destroy that change when I stop the subscription/move to another route.
Is that possible somehow?
Thank you for your answer.
Upvotes: 1
Views: 287
Reputation: 8360
I would use a transformation on the client, like this:
var Books = new Meteor.Collection('books', {
transform: function(doc){
/*
A doc looks like this:
{
_id: "...",
title: "A nice title..."
}
*/
doc.clientTitle = new ReactiveVar("")
doc.setClientTitle = function(title){
this.clientTitle.set(title)
}
doc.getTitle = function(){
var clientTitle = this.clientTitle.get()
if(clientTitle == ""){
return this.title
}else{
return clientTitle
}
}
}
})
and then use theBook.getTitle()
to get the title and theBook.setTitle('The new title')
to update it on the client only.
Note: ReactiveVar
comes from the package reactive-var
.
Upvotes: 0