mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
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.
This commit is contained in:
parent
3ec5375fbd
commit
8cfbc7f9af
2 changed files with 34 additions and 15 deletions
|
@ -2,7 +2,6 @@
|
|||
<div class="grid submit">
|
||||
{{#with post}}
|
||||
<form class="grid-block form-horizontal">
|
||||
{{#constant}}
|
||||
<div class="control-group">
|
||||
<label class="control-label">Title</label>
|
||||
<div class="controls"><input id="title" type="text" value="{{headline}}" /></div>
|
||||
|
@ -15,7 +14,6 @@
|
|||
<label class="control-label">Body</label>
|
||||
<div class="controls" id="editor"><textarea id="body" value="" class="input-xlarge">{{body}}</textarea></div>
|
||||
</div>
|
||||
{{/constant}}
|
||||
<div class="form-actions">
|
||||
<a class="delete-link" href="/posts/deleted">Delete Post</a>
|
||||
<input type="submit" value="Submit" />
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue