Skip to content

$init helper #91

Answered by KevinBatdorf
SimoTod asked this question in Ideas
Feb 14, 2021 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

The only worry I have with any sort of init type functionality is that Caleb mentioned in (alpinejs/alpine#1015 (comment)) that x-init will behave differently in V3 so it might be good to wait and see how it changes and whether there's a better way to extend it.

Possibly we can support x-text="$init('foo', expression, 'bar')" which would set foo the first time but will return foo.bar`.

What you described sounds more like x-text="$waitFor('foo', (v) => v.bar)" or

<div x-data="{ product: 'Loading...' }">
  <p x-text="$waitFor(
    $cache('product', () => expensiveLongCalculation(), 300),
    (result) => result.description
  )">

$waitFor() would be waiting for an initial change (instead of…

Replies: 2 comments 1 reply

Comment options

SimoTod
Feb 14, 2021
Maintainer Author

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@SimoTod
Comment options

SimoTod Feb 14, 2021
Maintainer Author

Answer selected by SimoTod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants