van icon indicating copy to clipboard operation
van copied to clipboard

expose isProps

Open DanielMazurkiewicz opened this issue 1 year ago • 2 comments

There is this fragment in tagsNS:

let [props, ...children] = protoOf(args[0] ?? 0) === objProto ? args : [{}, ...args]

and for the sake of possibility of creating semi "custom tags" I would want to get exposed isProps to be able to detect if props are provided as first argument to my function:

let isProps = (o) => protoOf(o ?? 0) === objProto

and then line in tagsNS would look like that:

let [props, ...children] = isProps(args[0]) ? args : [{}, ...args]

If no one using isProps minifier should inline it back, so no size impact.

DanielMazurkiewicz avatar Dec 13 '23 11:12 DanielMazurkiewicz

Thanks for the suggestion!

My current feeling is that since isProps function is quite easy to add on the client side (a just a couple lines of change) it probably doesn't have too much value to add another top-level function to VanJS.

btw: All top-level functions of VanJS are nested into a single van object when being exported. Thus that's not something minifier can trim off (this might be a design mistake of VanJS, but it's too late to fix).

Tao-VanJS avatar Dec 14 '23 00:12 Tao-VanJS

btw: All top-level functions of VanJS are nested into a single van object when being exported. Thus that's not something minifier can trim off (this might be a design mistake of VanJS, but it's too late to fix).

Paste this code:

const test0 = () => console.log("test0");

const namespace = {
    test1: () => test0(),
    test2: () => console.log("test2")
}

namespace.test1();

here:

https://try.terser.org/

To me looks like nothing that need to be fixed or changed with VanJS, whatever not used gets wiped out, whatever used once, gets inlined.

DanielMazurkiewicz avatar Dec 14 '23 08:12 DanielMazurkiewicz