FIX: Composer preview not caching inline onebox.

This commit is contained in:
Guo Xiang Tan
2019-06-11 09:13:39 +08:00
parent 9168ffc201
commit bd538f7437
7 changed files with 48 additions and 17 deletions

View File

@@ -0,0 +1,5 @@
export const INLINE_ONEBOX_LOADING_CSS_CLASS =
"<%= CookedPostProcessor::INLINE_ONEBOX_LOADING_CSS_CLASS %>";
export const INLINE_ONEBOX_CSS_CLASS =
"<%= CookedPostProcessor::INLINE_ONEBOX_CSS_CLASS %>";

View File

@@ -1,10 +1,10 @@
import { lookupCache } from "pretty-text/oneboxer";
import { cachedInlineOnebox } from "pretty-text/inline-oneboxer";
import {
cachedInlineOnebox,
INLINE_ONEBOX_LOADING_CSS_CLASS,
INLINE_ONEBOX_CSS_CLASS
} from "pretty-text/inline-oneboxer";
} from "pretty-text/context/inline-onebox-css-classes";
const ONEBOX = 1;
const INLINE = 2;
@@ -105,7 +105,7 @@ function applyOnebox(state, silent) {
if (onebox && onebox.title) {
text.content = onebox.title;
attrs.push(["class", INLINE_ONEBOX_CSS_CLASS]);
} else {
} else if (!onebox) {
attrs.push(["class", INLINE_ONEBOX_LOADING_CSS_CLASS]);
}
}

View File

@@ -1,10 +1,9 @@
let _cache = {};
import {
INLINE_ONEBOX_LOADING_CSS_CLASS,
INLINE_ONEBOX_CSS_CLASS
} from "pretty-text/context/inline-onebox-css-classes";
export const INLINE_ONEBOX_LOADING_CSS_CLASS =
"<%= CookedPostProcessor::INLINE_ONEBOX_LOADING_CSS_CLASS %>";
export const INLINE_ONEBOX_CSS_CLASS =
"<%= CookedPostProcessor::INLINE_ONEBOX_CSS_CLASS %>";
const _cache = {};
export function applyInlineOneboxes(inline, ajax) {
Object.keys(inline).forEach(url => {
@@ -20,7 +19,8 @@ export function applyInlineOneboxes(inline, ajax) {
_cache[onebox.url] = onebox;
let links = inline[onebox.url] || [];
links.forEach(link => {
$(link).text(onebox.title)
$(link)
.text(onebox.title)
.addClass(INLINE_ONEBOX_CSS_CLASS)
.removeClass(INLINE_ONEBOX_LOADING_CSS_CLASS);
});
@@ -32,3 +32,11 @@ export function applyInlineOneboxes(inline, ajax) {
export function cachedInlineOnebox(url) {
return _cache[url];
}
export function applyCachedInlineOnebox(url, onebox) {
return (_cache[url] = onebox);
}
export function deleteCachedInlineOnebox(url) {
return delete _cache[url];
}

View File

@@ -1,7 +1,7 @@
import {
INLINE_ONEBOX_CSS_CLASS,
INLINE_ONEBOX_LOADING_CSS_CLASS
} from "pretty-text/inline-oneboxer";
INLINE_ONEBOX_LOADING_CSS_CLASS,
INLINE_ONEBOX_CSS_CLASS
} from "pretty-text/context/inline-onebox-css-classes";
// to match:
// abcd