Giter VIP home page Giter VIP logo

Comments (4)

chinedufn avatar chinedufn commented on May 15, 2024

So I've just been adding features to Pecy as I've needed them for some sites that I'm working on or as other people have needed them.
So our event story is still a work in progress.


I'm curious about what you think would be ideal here?


Would something like generally work for you / feel correct?

let input = html! { 
  <input type="text", !oninput=|mouse_event: web_sys::MouseEvent|  {
   //...
  },></input>
  };

I think we might be able to do this pretty easily (emphasis on think.. I'm just going off the top of my head..)

Here's what I'm thinking:


Right now we store our events as wasm-bindgen Closure's

pub struct Events(pub HashMap<String, RefCell<Option<Closure<Fn() -> ()>>>>);

This prevents us from being able to have different events with different arguments since we're clearly specifying Fn() -> () there.

If we instead stored Function's we could have whatever signatures we wanted.

So instead of converting the callback into a Function here

.add_event_listener_with_callback(event, callback.as_ref().unchecked_ref())

We'd convert it here, right before adding it to the VirtualNode (using unchecked_into instead of unchecked_ref I think..?

$crate::RefCell::new(Some($crate::Closure::new($callback)))

Then Events here

pub struct Events(pub HashMap<String, RefCell<Option<Closure<Fn() -> ()>>>>);

would probably change to store Function instead of Closure


Curious about your thoughts here! If this implementation makes sense I've be more than happy to answer absolutely any questions / clarify any of the above.

Otherwise I've already set aside time 2 weeks from now to work on Percy's router and re-writing the html! macro as a procedural macro so I could also address this at that time.

At any rate.. Thanks a lot for opening up this issue! Keep them coming! We definitely want to prioritize things that people need right now so this is great.

from percy.

chinedufn avatar chinedufn commented on May 15, 2024

Ok so I actually started taking a look at implementing this and it's slightly more complicated than I laid out.

I'll think a bit and get back to ya

from percy.

chinedufn avatar chinedufn commented on May 15, 2024

Ok I think the way to go here is to just add macro rules for each type of input

oninput ontext.. etc

There's a finite number that isn't very large. If someone needs a custom event listener they can use the old !myevent = || {} syntax.

I'll get a unit test and implementation for this in a PR and tag you. Then we can use that as an example for adding new events over time as we need them!

from percy.

chinedufn avatar chinedufn commented on May 15, 2024

Alright the codes messy and a work in progress but I have a branch with a failing test case

image

Note that this test is a little off since I'm asserting for text that isn't even in the input event.. I'll fix this up..

image

51d6463

I Should have time this weekend to get this working

Again.. code isn't cleaned up at all just sharing the progress

from percy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.