In this reproduction I'm trying to understand if it's possible and if this is the idiomatic way to create a condition filter for a list merging variables from parents too...
But it doesn't work.
As you can see, when you open the project the condition is empty {}
.
Instead I need it to be:
{"or": [ {"withPlayer": {"name": "testMe" } } ]}
Is there a way?
App.svelte:
<script> import List from "./List.svelte";</script><List searchText={"testMe"} />
List.svelte:
<script> let { pagination = { current: 1, size: 5 }, condition = {}, searchText } = $props(); const facade = { get searchText() { return searchText }, set searchText(value) { searchText = value; condition.or = (condition.or || []).filter((item) => !item.withPlayer); if (value) { condition.or.push({ withPlayer: { name: value } }); } } }</script><input type="text" bind:value={facade.searchText} /><br><br>condition: <pre>{JSON.stringify(condition, null, 2)}</pre>
I can add facade.searchText = searchText;
to the end of the script, but in this example I only have searchText
but in real code I have many of them and is not easy to remember to add all of them at the end of the script when I add or remove props.
Any idea?