Skip to content

Commit 8e08e1c

Browse files
committed
implement #358
1 parent d71f853 commit 8e08e1c

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

exampleVault/Buttons/Button Example.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
count: -1
2+
count: 0
33
someList:
44
- 1708945050652
55
- 1709918700548
@@ -246,7 +246,21 @@ actions:
246246
247247
```
248248

249-
`BUTTON[count-decrement, count-reset, count-increment]` `VIEW[{count}]`
249+
Count: `BUTTON[count-decrement, count-reset, count-increment]` `VIEW[{count}]`
250+
251+
```meta-bind-button
252+
label: "Add count to count2"
253+
hidden: false
254+
style: default
255+
actions:
256+
- type: updateMetadata
257+
bindTarget: count2
258+
evaluate: true
259+
value: "x + getMetadata('count')"
260+
261+
```
262+
263+
Count2: `VIEW[{count2}]`
250264

251265
```meta-bind-button
252266
label: Add Current Time to List

packages/core/src/fields/button/ButtonActionRunner.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
import { MDLinkParser } from 'packages/core/src/parsers/MarkdownLinkParser';
2222
import { expectType, openURL } from 'packages/core/src/utils/Utils';
2323
import { parseLiteral } from 'packages/core/src/utils/Literal';
24-
2524
import { type NotePosition } from 'packages/core/src/config/APIConfigs';
2625
import { ErrorLevel, MetaBindJsError, MetaBindParsingError } from 'packages/core/src/utils/errors/MetaBindErrors';
2726

@@ -293,9 +292,16 @@ export class ButtonActionRunner {
293292
}
294293

295294
// eslint-disable-next-line @typescript-eslint/no-implied-eval
296-
const func = new Function('x', `return ${action.value};`) as (value: unknown) => unknown;
297-
298-
this.plugin.api.updateMetadata(bindTarget, func);
295+
const func = new Function('x', 'getMetadata', `return ${action.value};`) as (
296+
value: unknown,
297+
getMetadata: (bindTarget: string) => unknown,
298+
) => unknown;
299+
300+
this.plugin.api.updateMetadata(bindTarget, value =>
301+
func(value, bindTarget => {
302+
return this.plugin.api.getMetadata(this.plugin.api.parseBindTarget(bindTarget, filePath));
303+
}),
304+
);
299305
} else {
300306
this.plugin.api.setMetadata(bindTarget, parseLiteral(action.value));
301307
}

0 commit comments

Comments
 (0)