最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Downsides to specifying createEffect() dependencies with no-op expressions in Solid? - Stack Overflow

programmeradmin10浏览0评论

I have some code like this:

    createEffect(() => {
        props.dynamicFeatures;      
        updateDynamicMapLayers()}
    })

Here, updateDynamicMapLayers() is a throttled function that seems to break Solid's automatic dependency checking.

This code works, but I've been told this isn't a good idea, without a clear reason. I'm told I should use this somewhat clunkier version:

createEffect(
    on(() => props.dynamicFeatures, updateDynamicMapLayers),
)

Is there any particular problem with the first way?

I have some code like this:

    createEffect(() => {
        props.dynamicFeatures;      
        updateDynamicMapLayers()}
    })

Here, updateDynamicMapLayers() is a throttled function that seems to break Solid's automatic dependency checking.

This code works, but I've been told this isn't a good idea, without a clear reason. I'm told I should use this somewhat clunkier version:

createEffect(
    on(() => props.dynamicFeatures, updateDynamicMapLayers),
)

Is there any particular problem with the first way?

Share Improve this question asked Feb 5 at 9:26 Steve BennettSteve Bennett 126k45 gold badges185 silver badges241 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 1

From the on docs:

on is designed to be passed into a computation to make its dependencies explicit.

createEffect(on(a, (v) => console.log(v, b())));

// is equivalent to:
createEffect(() => {
  const v = a();
  untrack(() => console.log(v, b()));
});

So it's mostly a matter of style. I'm not sure, but Solid might also not give any guarantees that your first version will continue to work. Accessing the props.dynamicFeatures signal without using the value might be optimized away in a future update.

If you don't like on, why not change your function to be explicit in its input? Like: updateDynamicMapLayers(props.dynamicFeatures)

发布评论

评论列表(0)

  1. 暂无评论