From 4ea7294eeb2aa71a48c984562750958dd92900de Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 19 Feb 2023 16:10:08 +0530 Subject: [PATCH] fix(#3406, #3394): Remove init & initThrowsErrors New run function added as replacement. --- V10-BreakingChanges.md | 35 ++- .../external-diagrams-example-diagram.html | 2 +- cypress/platform/render-after-error.html | 3 +- cypress/platform/rerender.html | 2 +- .../interfaces/mermaidAPI.ParseOptions.md | 19 ++ .../interfaces/mermaidAPI.RenderResult.md | 4 +- docs/config/setup/modules/mermaidAPI.md | 25 +-- packages/mermaid/src/mermaid.spec.ts | 28 ++- packages/mermaid/src/mermaid.ts | 202 ++++++++++-------- packages/mermaid/src/mermaidAPI.spec.ts | 4 +- packages/mermaid/src/mermaidAPI.ts | 17 +- 11 files changed, 215 insertions(+), 126 deletions(-) create mode 100644 docs/config/setup/interfaces/mermaidAPI.ParseOptions.md diff --git a/V10-BreakingChanges.md b/V10-BreakingChanges.md index e3322a3a1..121fdd596 100644 --- a/V10-BreakingChanges.md +++ b/V10-BreakingChanges.md @@ -2,7 +2,7 @@ ## Async -`init`, `parse`, `render` are now async. +`parse`, `render` are now async. ## Lazy loading and asynchronisity @@ -23,3 +23,36 @@ try { parseError(err); } ``` + +## Init deprecated and InitThrowsErrors removed + +The config passed to `init` was not being used eariler. +It will now be used. +The `init` function is deprecated and will be removed in the next major release. +init currently works as a wrapper to `initialize` and `run`. + +```js +//< v10.0.0 +mermaid.init(config, selector, cb); + +//>= v10.0.0 +mermaid.initialize(config); +mermaid.run({ + querySelector: selector, + postRenderCallback: cb, + suppressErrors: true, +}); +``` + +```js +//< v10.0.0 +mermaid.initThrowsErrors(config, selector, cb); + +//>= v10.0.0 +mermaid.initialize(config); +mermaid.run({ + querySelector: selector, + postRenderCallback: cb, + suppressErrors: false, +}); +``` diff --git a/cypress/platform/external-diagrams-example-diagram.html b/cypress/platform/external-diagrams-example-diagram.html index a1339d4e6..b5b716ff8 100644 --- a/cypress/platform/external-diagrams-example-diagram.html +++ b/cypress/platform/external-diagrams-example-diagram.html @@ -17,7 +17,7 @@ example-diagram await mermaid.registerExternalDiagrams([exampleDiagram]); await mermaid.initialize({ logLevel: 0 }); - await mermaid.initThrowsErrors(); + await mermaid.run(); if (window.Cypress) { window.rendered = true; } diff --git a/cypress/platform/render-after-error.html b/cypress/platform/render-after-error.html index 72ccac34c..2334158c2 100644 --- a/cypress/platform/render-after-error.html +++ b/cypress/platform/render-after-error.html @@ -11,7 +11,8 @@