DEV: Start renaming cookAsync() function to cook() (#23462)

Some time ago, we introduced the `cookAsync` instead of the existing 
`cook` function, and planned to migrate everything to it. Then after 
migrating, we wanted to raname the function to simply `cook`.

I've checked Core and plugins, and currently we call `cookAsync` everywhere, 
there are no calls to the `cook` function anymore. So we're good 
to proceed with this refactoring.

This PR makes the first step by making current cookAsync and cook functions 
do the same thing. Effectively now the `cook` function becomes an alias 
for the `cookAsync` function.
This commit is contained in:
Andrei Prigorshnev
2023-10-09 20:22:46 +04:00
committed by GitHub
parent 62c7a54f88
commit fcc9d99ba2
12 changed files with 37 additions and 37 deletions

View File

@ -1,6 +1,6 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import { cookAsync } from "discourse/lib/text";
import { cook } from "discourse/lib/text";
import Post from "discourse/models/post";
import { checklistSyntax } from "discourse/plugins/checklist/discourse/initializers/checklist";
import { Promise } from "rsvp";
@ -8,7 +8,7 @@ import { Promise } from "rsvp";
let currentRaw;
async function prepare(raw) {
const cooked = await cookAsync(raw, {
const cooked = await cook(raw, {
siteSettings: { checklist_enabled: true },
});

View File

@ -6,7 +6,7 @@ import Component from "@ember/component";
import EmberObject, { action } from "@ember/object";
import I18n from "I18n";
import { INPUT_DELAY } from "discourse-common/config/environment";
import { cookAsync } from "discourse/lib/text";
import { cook } from "discourse/lib/text";
import { notEmpty } from "@ember/object/computed";
import { propertyNotEqual } from "discourse/lib/computed";
import { schedule } from "@ember/runloop";
@ -59,7 +59,7 @@ export default Component.extend({
@debounce(INPUT_DELAY)
async _renderPreview() {
if (this.markup) {
const result = await cookAsync(this.markup);
const result = await cook(this.markup);
this.set("currentPreview", result);
schedule("afterRender", () => {

View File

@ -1,13 +1,11 @@
import Component from "@ember/component";
import { cookAsync } from "discourse/lib/text";
import { cook } from "discourse/lib/text";
export default Component.extend({
didInsertElement() {
this._super(...arguments);
const contents = $(this.element).html();
cookAsync(contents).then((cooked) =>
$(this.element).html(cooked.toString())
);
cook(contents).then((cooked) => $(this.element).html(cooked.toString()));
},
});