Skip to content

Commit 524678e

Browse files
committed
refactor: 精简代码
1 parent b485b5e commit 524678e

2 files changed

Lines changed: 5 additions & 20 deletions

File tree

src/components/BootstrapBlazor.Vditor/Vditor.razor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
9292
if (_lastValue != Value)
9393
{
9494
_lastValue = Value;
95-
await InvokeVoidAsync("setValue", Id, Value);
95+
await InvokeVoidAsync("execute", Id, "setValue", new object?[] { Value, true });
9696
}
9797
}
9898

@@ -126,7 +126,7 @@ public async Task Reset(string value, VditorOptions options)
126126
/// </summary>
127127
/// <param name="value"></param>
128128
/// <param name="render"></param>
129-
public Task InsertValueAsync(string? value, bool render = true) => InvokeVoidAsync("insertValue", Id, value, render);
129+
public Task InsertValueAsync(string? value, bool render = true) => InvokeVoidAsync("execute", Id, "insertValue", new object?[] { value, render });
130130

131131
/// <summary>
132132
/// <para lang="zh">获取编辑器的 Markdown 内容</para>

src/components/BootstrapBlazor.Vditor/Vditor.razor.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,15 @@ export async function reset(id, value, options) {
4444
}
4545
}
4646

47-
export function setValue(id, value) {
48-
const md = Data.get(id);
49-
const { vditor } = md;
50-
if (vditor) {
51-
vditor.setValue(value, true);
52-
}
53-
}
54-
55-
export function insertValue(id, value, render) {
56-
const md = Data.get(id);
57-
const { vditor } = md;
58-
if (vditor) {
59-
vditor.insertValue(value, render);
60-
}
61-
}
62-
63-
export function execute(id, method) {
47+
export function execute(id, method, args) {
48+
console.log(method, args);
6449
const md = Data.get(id);
6550
const { vditor } = md;
6651
let ret = '';
6752
if (vditor) {
6853
var cb = vditor[method];
6954
if (cb) {
70-
ret = cb.call(vditor);
55+
ret = cb.call(vditor, ...(args || []));
7156
}
7257
}
7358
return ret;

0 commit comments

Comments
 (0)