Skip to content

Commit a2bfe97

Browse files
committed
add validation to API
1 parent 3c4478d commit a2bfe97

File tree

8 files changed

+547
-228
lines changed

8 files changed

+547
-228
lines changed

exampleVault/Advanced Examples/Using JS Engine for Complex things.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const mb = engine.getPlugin('obsidian-meta-bind-plugin').api;
1010
const comp = new obsidian.Component(component);
1111
1212
// create a bind target to the property that we care about
13-
const bindTarget = mb.bindTargetParser.fromStringAndValidate('locked', context.file.path);
13+
const bindTarget = mb.parseBindTarget('locked', context.file.path);
1414
1515
// the render function, it takes the locked value as the argument
1616
function render(value) {
@@ -34,10 +34,10 @@ function render(value) {
3434
}
3535
3636
// we create a reactive component from the render function and the initial value will be the value of the bind target
37-
const reactive = engine.reactive(render, mb.getMetadataWithBindTarget(bindTarget));
37+
const reactive = engine.reactive(render, mb.getMetadata(bindTarget));
3838
3939
// then we subscribe to the metadata that the bind target points to and rerender the reactive component everythime the bind target value changes
40-
const subscription = mb.subscribeToMetadataWithBindTarget(
40+
const subscription = mb.subscribeToMetadata(
4141
bindTarget,
4242
(value) => reactive.refresh(value)
4343
);
@@ -51,21 +51,20 @@ return reactive;
5151
```js-engine
5252
const mb = engine.getPlugin('obsidian-meta-bind-plugin').api;
5353
54+
const bindTarget = mb.parseBindTarget('text', context.file.path);
55+
5456
function onUpdate(value) {
5557
return value.toString();
5658
}
5759
58-
const reactive = engine.reactive(onUpdate, context.metadata.frontmatter.text);
60+
const reactive = engine.reactive(onUpdate, mb.getMetadata(bindTarget));
5961
6062
const subscription = mb.subscribeToMetadata(
61-
'frontmatter',
62-
context.file.path,
63-
['text'],
64-
false,
63+
bindTarget,
6564
(value) => reactive.refresh(value)
6665
);
6766
6867
component.register(() => subscription.unsubscribe());
6968
7069
return reactive;
71-
```
70+
```

0 commit comments

Comments
 (0)