REFACTOR: Use component for `cook-text` to improve async workflow
This commit is contained in:
parent
aa1a68b979
commit
6ff7bf7505
|
@ -0,0 +1,15 @@
|
||||||
|
import { cookAsync } from 'discourse/lib/text';
|
||||||
|
|
||||||
|
const CookText = Ember.Component.extend({
|
||||||
|
tagName: '',
|
||||||
|
cooked: null,
|
||||||
|
|
||||||
|
didReceiveAttrs() {
|
||||||
|
this._super(...arguments);
|
||||||
|
cookAsync(this.get('rawText')).then(cooked => this.set('cooked', cooked));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
CookText.reopenClass({ positionalParams: ['rawText'] });
|
||||||
|
|
||||||
|
export default CookText;
|
|
@ -1,18 +0,0 @@
|
||||||
import { cookAsync } from 'discourse/lib/text';
|
|
||||||
import guid from 'pretty-text/guid';
|
|
||||||
import { registerUnbound } from 'discourse-common/lib/helpers';
|
|
||||||
|
|
||||||
function cookText(text) {
|
|
||||||
const id = `${guid().replace(/-/g, '')}`;
|
|
||||||
|
|
||||||
cookAsync(text)
|
|
||||||
.then(cooked => {
|
|
||||||
Em.run.next(()=>{
|
|
||||||
$('#' + id).html(cooked.string);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return new Handlebars.SafeString(`<div id='${id}'></div>`);
|
|
||||||
}
|
|
||||||
|
|
||||||
registerUnbound('cook-text', cookText);
|
|
|
@ -0,0 +1 @@
|
||||||
|
{{cooked}}
|
|
@ -34,7 +34,7 @@
|
||||||
{{#if editing}}
|
{{#if editing}}
|
||||||
{{d-editor value=buffered.raw}}
|
{{d-editor value=buffered.raw}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{{cook-text post.raw}}}
|
{{cook-text post.raw}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue