topics: improve handling topics without callbacks subscribed

This commit is contained in:
Marcin Lulek 2016-07-18 14:28:06 +02:00
parent a03e4a88f9
commit a537335516
4 changed files with 13 additions and 4 deletions

View file

@ -384,7 +384,7 @@ $(document).ready(function() {
tr[0].scrollIntoView();
$.Topic('/ui/plugins/code/anchor_focus').prepare({
$.Topic('/ui/plugins/code/anchor_focus').prepareOrPublish({
tr:tr,
remainder:remainder});
}

View file

@ -210,7 +210,7 @@ var injectInlineForm = function(tr){
}
}, 10);
$.Topic('/ui/plugins/code/comment_form_built').prepare({
$.Topic('/ui/plugins/code/comment_form_built').prepareOrPublish({
form:_form,
parent:_parent}
);

View file

@ -32,6 +32,14 @@ jQuery.Topic = function (id) {
this.unhandledData.push(arguments[i]);
}
},
prepareOrPublish: function(){
if (callbacks.has() === true){
this.publish.apply(this, arguments);
}
else{
this.prepare.apply(this, arguments);
}
},
processPrepared: function(){
var data = this.unhandledData;
this.unhandledData = [];
@ -40,7 +48,8 @@ jQuery.Topic = function (id) {
}
},
subscribe: callbacks.add,
unsubscribe: callbacks.remove
unsubscribe: callbacks.remove,
callbacks: callbacks
};
if (id) {
topics[id] = topic;

View file

@ -10,5 +10,5 @@ ${pyramid_render(config['template_hooks'].get('plugin_init_template'),
% endif
% endfor
<script>
$.Topic('/plugins/__REGISTER__').publish({});
$.Topic('/plugins/__REGISTER__').prepareOrPublish({});
</script>