From 8cfbc7f9af96999cd9951d6e9946e91c57666c8a Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Tue, 2 Oct 2012 11:59:22 +1000 Subject: [PATCH] Isolated Posts to be non-reactive on post_edit. The idea here is to isolate the call to findOne() so that it stops being reactive once data is found. The reason being that server scoring updates will 'change' the post, and meteor will overwrite the user's input, even if preserve is set. Kind of like {{#constant}}, except it waits for data. --- client/templates/post_edit.html | 26 ++++++++++++-------------- client/templates/post_edit.js | 23 ++++++++++++++++++++++- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/client/templates/post_edit.html b/client/templates/post_edit.html index 2cd91d34d..d4c1a93c2 100644 --- a/client/templates/post_edit.html +++ b/client/templates/post_edit.html @@ -2,20 +2,18 @@
{{#with post}}
- {{#constant}} -
- -
-
-
- -
-
-
- -
-
- {{/constant}} +
+ +
+
+
+ +
+
+
+ +
+
Delete Post diff --git a/client/templates/post_edit.js b/client/templates/post_edit.js index 6605ff715..ffa03f232 100644 --- a/client/templates/post_edit.js +++ b/client/templates/post_edit.js @@ -2,7 +2,28 @@ Template.post_edit.helpers({ post: function(){ - return Posts.findOne(Session.get('selectedPostId')); + // The idea here is to isolate the call to findOne() so that it stops + // being reactive once data is found. The reason being that server scoring + // updates will 'change' the post, and meteor will overwrite the user's + // input, even if preserve is set. + // Kind of like {{#constant}}, except it waits for data. + // + // XXX: either figure out a different approach, or factor this out and + // use everywhere. + var outerContext = Meteor.deps.Context.current; + var innerContext = new Meteor.deps.Context; + var post; + + innerContext.onInvalidate(function() { + // we don't need to send the invalidate through anymore if post is set + post || outerContext.invalidate(); + }); + + innerContext.run(function() { + post = Posts.findOne(Session.get('selectedPostId')); + }) + + return post; } });