Intelephense / Livewire - Decorators are not valid here

175 views Asked by At

I'm using the vscode intelephense extension, and writing some JS logic using laravel livewire. My objective is to send an event at a specific time to refresh some data.

To achieve this, my logic is something like:

document.addEventListener('livewire:load', function () {
    const refreshTime = @this.refreshTime;
    setTimeout(() => {
        Livewire.emit('refresh');
    }, refreshTime);
});

Although this works, the Intelephense extension reports an error on @this.refreshTime:

Decorators are not valid here.javascript
Expression expected.javascript

Is there any way to prevent or ignore this error? I'm thinking something like eslint-disable-next-line, but for intelephense. Solutions that avoid using @this, @js, and other invalid JS syntax would also be acceptable!

1

There are 1 answers

0
Brian Hannay On

My current solution for this is to populate the data in an element:

<div
    class="hidden"
    id="editor-data"
    data-refresh-time="{{ $refreshTime }}"
>
</div>

And retrieve the values using the element's dataset. In my case, the element will only appear once per page, so I don't need to worry about ID collisions.

document.addEventListener('livewire:load', function () {
    const dataEl = document.getElementById('editor-data');
    const refreshTime = parseInt(dataEl.dataset.refreshTime);
    setTimeout(() => {
        Livewire.emit('refresh');
    }, refreshTime);
});