gnat / surreal

🗿 Mini jQuery alternative. Dependency-free animations. Locality of Behavior. Use one element or arrays transparently. Pairs with htmx. Vanilla querySelector() but better!
https://gnat.github.io/surreal/example.html
MIT License
1.2k stars 24 forks source link

Warning cannot be surpressed due to incorrect parameter order #21

Closed brablc closed 6 months ago

brablc commented 6 months ago

I have this code:

me().on('click', (ev) => { me('#sidebar-toggle.initially-closed', document, false)?.send('click'); });

The third parameter should supress warning in console when the class is not set. But the warning is generated to console:

Surreal: "#sidebar-toggle.initially-closed" was not found. Missing a character? (. #)

gnat commented 6 months ago

Great catch, will try this out and merge your PR or resolve this soon.

gnat commented 6 months ago

Thanks @brablc.

Resolved in 1.1.8, ended up simplifying the internal isSelector() function: https://github.com/gnat/surreal/commit/faa3b6ced3ad9a48d7f7c02bf9a630ab6d86c3b4

Your code should now work fine with the update.

gnat commented 6 months ago

@brablc Added a tip about this: https://github.com/gnat/surreal/blob/main/README.md#-conventions--tips

brablc commented 6 months ago

While we are at it, I believe this does not work as shown in documentation.

any('button', start='header').classAdd('red')

Proper code would be:

any('button', me('header')).classAdd('red')

Or if you prefer to assign to variable which would not be used:

any('button', start=me('header')).classAdd('red')

But I do not like that, it may mislead someone that named parameters are already supported (been there ;-).

gnat commented 6 months ago

Perfect @brablc ! Thanks for the corrections. For sure an oversight.

Before image

After image

it may mislead someone that named parameters are already supported

lmao, I know right?