--
You received this message because you are subscribed to the Google Groups "meteor-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meteor-core...@googlegroups.com.
To post to this group, send email to meteo...@googlegroups.com.
Visit this group at http://groups.google.com/group/meteor-core.
To view this discussion on the web visit https://groups.google.com/d/msgid/meteor-core/9bee4f62-3b53-4b38-9bf6-eb197752c5c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
My understanding is that a 'transform' function allows to modify the result of a query. I don't think it allows to store data. Am I missing something?
--
You received this message because you are subscribed to the Google Groups "meteor-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meteor-core...@googlegroups.com.
To post to this group, send email to meteo...@googlegroups.com.
Visit this group at http://groups.google.com/group/meteor-core.
To view this discussion on the web visit https://groups.google.com/d/msgid/meteor-core/974881b6-6eb1-485f-911a-53f15c6ce163%40googlegroups.com.
What I want is to store some additional data on the client-side.I can use 'transform' to add some data to a query result, but where do I get that data from?
--
You received this message because you are subscribed to the Google Groups "meteor-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meteor-core...@googlegroups.com.
To post to this group, send email to meteo...@googlegroups.com.
Visit this group at http://groups.google.com/group/meteor-core.
To view this discussion on the web visit https://groups.google.com/d/msgid/meteor-core/ad365d35-281d-4b20-b8aa-b6c9fe76a567%40googlegroups.com.
Test = new Mongo.Collection('test');
newId = Test._collection.insert({});
Test._collection.update(newId, {$set: {name: 'Roman'}});
Meteor.call('saveTestRecord', Test.findOne(newId), function (err) {
Test._collection.remove(newId);
});
For reference, I think there are two more options to consider:
- Creating a independent reactive structure using Tracker.Dependency (I guess ViewModel is implemented this way).
- Creating an unmanaged (unsynchronized) local collection ("myClientSideCollection = new Mongo.Collection(null)").
It seems to me ViewModel is based on a static description of a UI, whereas mine (the tree) is dynamic and has to match a changing collection...
Collection._collection.update(data)
Meteor.call('/collection/update/', data, function(){})
As I said earlier, this is easily solved with a combination of local collection and cursor.observeChanges.
If we talk about hot code push there is no way to store any states, except of amplify.store and amplify pub/sub.
But I guess that hot code push is dev-only feature and you can store states in Session variable or ReactiveVar for example. Hot code push in production is a really rare case and it implies global client-side drop.
My understanding is that a 'transform' function allows to modify the result of a query. I don't think it allows to store data. Am I missing something?
Session.setDefault('messages', {});
var transform = function(doc) { var read = Session.get('messages'); // add a flag read to the documnent doc.read = doc._id in read; return doc;};
Template.hello.helpers({
messages: function() {
// make reactive by looking at messages var m = Session.get('messages'); return Messages.find({},{transform: transform});
}
});
<ul> {{#each messages}} <li> {{#if read}} <span class="read">{{subject}}</span> {{else}} {{subject}} <button messageid="{{_id}}" class="markread">Mark Read</button> {{/if}} </li> {{/each}} </ul>
--
You received this message because you are subscribed to the Google Groups "meteor-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meteor-core...@googlegroups.com.
To post to this group, send email to meteo...@googlegroups.com.
Visit this group at http://groups.google.com/group/meteor-core.
To view this discussion on the web visit https://groups.google.com/d/msgid/meteor-core/159687f5-1e4f-4209-a536-70e71fba5a6a%40googlegroups.com.
Transform is run on every single object. That is where you would set the default value based on the object's properties.
On Fri Nov 28 2014 at 9:36:28 AM steph643 <sylvain...@gmail.com> wrote:
@Jan, you suggest to store UI status in a Session variable, which is the usual way. The 'tansform' function is just an optional way to make UI status available through collection queries.--However, please let me point out two important drawbacks of your method (besides the fact that using 'transform' is probably not the right way to go, and obliges you to use a hack to trigger reactivity):
- In your example, the 'read' flag is false by default. Suppose you want it, by default, to be true or false depending on some conditions. Where would you put this initialization?
- If docs are added/removed from the database during a session, how do you add/remove them from your session variable? (unless you can afford the session variable to grow indefinitely)
The solution I proposed earlier solves these two issues in a short and generic way.
You received this message because you are subscribed to the Google Groups "meteor-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meteor-core+unsubscribe@googlegroups.com.