Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web-sys listener conversion #813

Merged
merged 19 commits into from
Jan 9, 2020
Merged

web-sys listener conversion #813

merged 19 commits into from
Jan 9, 2020

Conversation

daxpedda
Copy link
Contributor

@daxpedda daxpedda commented Dec 15, 2019

Do we really really want to support both stdweb and js-sys/web-sys? I find it far more compelling to switch completely. There are so many issues with compatibility and making a similar interface is really hard.

So I would like to propose that we just make a different branch where we can work on the web-sys migration without having to support both at the same time.

Cc #558, #826, #817, #818, #827, #841.

@jstarry
Copy link
Member

jstarry commented Dec 17, 2019

Have you looked at using gloo? https://github.com/rustwasm/gloo/blob/master/crates/events/src/lib.rs

I would love if Yew used gloo so that we could help build out the common modules they are building

@daxpedda
Copy link
Contributor Author

Sadly gloo really has very little that we can reuse.

Specifically the EventListener that they are implementing doesn't really work out for us because it removes the event on drop, which doesn't align with our current implementation.

@daxpedda
Copy link
Contributor Author

I took some inspiration from gloo and was able to remove the generic.

@daxpedda
Copy link
Contributor Author

daxpedda commented Dec 18, 2019

This part is done basically, changing Listener::attach to use web_sys::Element would break almost everything, so I'm going to put this in the next PR.

  • I called the feature web-sys, any other name we want to use here?
  • The macro is way more complicated now, is this alright or are there any good ideas to improve this?

@jstarry
Copy link
Member

jstarry commented Dec 18, 2019

This part is done basically, changing Listener::attach to use web_sys::Element would break almost verything, so I'm going to put this in the next PR.

  • I called the feature web-sys, any other name we want to use here?
  • The macro is way more complicated now, is this alright or are there any good ideas to improve this?

Awesome! Great work! This is probably the most daunting part of dual-support for stdweb / web-sys

Thanks for splitting up the work, I'm not sure if this PR is shippable though. I'm thinking it might be a good candidate for a feature branch until the bulk of the work is done. Thoughts?

I called the feature web-sys, any other name we want to use here?

web-sys is great

The macro is way more complicated now, is this alright or are there any good ideas to improve this?

More macros! 😆 But actually... 😉 I think some extra macro nesting could clean up the implementation / repetition. I'm cool with that coming later

@jstarry
Copy link
Member

jstarry commented Dec 18, 2019

Sadly gloo really has very little that we can reuse.

Specifically the EventListener that they are implementing doesn't really work out for us because it removes the event on drop, which doesn't align with our current implementation.

Ah that's a bummer, could you add an internal comment in the code to explain in detail why we can't use gloo here? I imagine as gloo gains more momentum there will be calls for Yew to integrate it

@daxpedda
Copy link
Contributor Author

I'm thinking it might be a good candidate for a feature branch until the bulk of the work is done. Thoughts?

Agreed.

I think some extra macro nesting could clean up the implementation / repetition. I'm cool with that coming later

There are some more issues that surfaced, I will most likely split the implementation into two files now 😞.

@jstarry
Copy link
Member

jstarry commented Dec 18, 2019

There are some more issues that surfaced, I will most likely split the implementation into two files now 😞.

No worries! Happy you're taking the time to get it right 👍

@jstarry jstarry changed the base branch from master to feature/web-sys December 18, 2019 16:16
@jstarry
Copy link
Member

jstarry commented Dec 18, 2019

A cleaner solution?

Yes, much cleaner!

@daxpedda
Copy link
Contributor Author

I was trying to abstract the Wrapper struct away, but apparently rust isn't very happy about macro invocation inside a macro, so this is the cleanest I'm getting.

@daxpedda daxpedda marked this pull request as ready for review December 18, 2019 19:38
@daxpedda
Copy link
Contributor Author

Just had an idea about how to solve that macro, I think this is as good as I will get it.

This was referenced Dec 19, 2019
@daxpedda daxpedda changed the base branch from feature/web-sys to web-sys December 27, 2019 11:00
@daxpedda
Copy link
Contributor Author

Moved it to the new web-sys branch.

@jstarry
Copy link
Member

jstarry commented Dec 29, 2019

Sorry for the delay, want to give this a closer look still. Holidays have been busy 😪

@richard-uk1
Copy link

Specifically the EventListener that they are implementing doesn't really work out for us because it removes the event on drop, which doesn't align with our current implementation.

The idea with gloo::events is that you can either use the RAII handle to avoid leaking memory, or call .forget() on the EventListener, which leaks the memory intentionally.

@daxpedda
Copy link
Contributor Author

daxpedda commented Jan 3, 2020

The idea with gloo::events is that you can either use the RAII handle to avoid leaking memory, or call .forget() on the EventListener, which leaks the memory intentionally.

Aha! I didn't see that it had it's own forget implementation, I wanted to leak as little as possible.
Will fix this soon.

src/html/listener/mod.rs Outdated Show resolved Hide resolved
src/html/listener/mod.rs Outdated Show resolved Hide resolved
@daxpedda
Copy link
Contributor Author

daxpedda commented Jan 4, 2020

Done.

@jstarry jstarry added this to the 0.12 milestone Jan 6, 2020
@jstarry
Copy link
Member

jstarry commented Jan 8, 2020

Specifically the EventListener that they are implementing doesn't really work out for us because it removes the event on drop, which doesn't align with our current implementation.

I'm not sure there's value in keeping consistent with our current implementation. I would rather that all event listeners get removed on drop. We don't expose event listener handles to the user right now anyways. Thoughts?

I think we could wrap the stdweb event listener handle so that we can remove on drop like we do here: https://github.com/yewstack/yew/blob/master/src/services/keyboard.rs#L88

@daxpedda
Copy link
Contributor Author

daxpedda commented Jan 8, 2020

Sounds good, I will be free in a couple of hours to do just that.

@daxpedda
Copy link
Contributor Author

daxpedda commented Jan 8, 2020

Done.

@jstarry
Copy link
Member

jstarry commented Jan 9, 2020

@daxpedda this requires a change to vtag.rs as well, it's still calling .remove() on the handlers. I think it's best to pull that change out of this PR and merge to master.

@daxpedda
Copy link
Contributor Author

daxpedda commented Jan 9, 2020

I already fixed that in the latest commit of #817.
Right? I hope I'm not missing something here.

@jstarry
Copy link
Member

jstarry commented Jan 9, 2020

I already fixed that in the latest commit of #817.

Ah ok, that's fine

@jstarry jstarry merged commit 7adfef1 into yewstack:web-sys Jan 9, 2020
@daxpedda daxpedda deleted the web-sys-listener branch January 9, 2020 09:19
jstarry added a commit that referenced this pull request Feb 29, 2020
* Enable travis

* `web-sys` general conversion (#826)

* Moved patches from different PRs.

* Add bits & pieces and some services.

* Rename `stdweb` feature to `std_web`.

* Move tests and examples to different PR.

* Revert some `cargo_web` handling removal.

* Missed something.

* Implement `console_error_panic_hook`.

* Update Cargo.toml

Co-authored-by: Justin Starry <justin.m.starry@gmail.com>

* Move document creation to util convenience method (#855)

* `web-sys` listener conversion (#813)

* `web-sys` listener initial try.

* Improve macros?

* Remove generic from `EventListenerHandle`.

* Fix build.

* A cleaner solution?

* Even cleaner.

* Fix `build.rs`.

* Minor improvements.

* Following the yew toml style.

* Fixing visibility.

* Fix `rustfmt`.

* Add `web-sys` re-exports.

* Move general changes to different PR.

* Remove compat.

* Actually remove `compat.rs`.

* Rename `stdweb` feature to `std_web`.

* Move to gloo's `EventListener` and some polish.

* Remove outdated comment.

* Change `EventHandler` to be cancelled on drop.

* `web-sys` html conversion (#817)

* Converting all `html` parts.

* Format.

* Move general changes to different PR.

* Removed compat.

* Rename `stdweb` feature to `std_web`.

* Remove redudant function copy.

* Some polish.

* Move to gloo's `EventListener`.

* Replace `unwrap`s with `expect`s.

* `web-sys` agent conversion (#818)

* Converting `agent`.

* Remove wrong `cfg` in imports.

* Move general changes to different PR.

* Some optimisations.

* Rename `stdweb` feature to `std_web`.

* Fix `ArrayBuffer` to `Uint8Array` conversions.

* Add js module worker.

* Use `cfg-if`` and `cfg-match` to make things clearer.

* Fix `std_web` build.

* Add some polish.

* Add build guards for invalid build configs (#866)

* `web_sys` cfg conversion (#862)

* Use `cfg-if` and `cfg-match` and some polish.

* Mistakes were made.

* Missed line during rebasing.

* Mistakes were undone.

* Remove global.

* Remove part of `global!`.

* `web-sys` services conversion (#827)

* Convert `console`.

* Finish services.

* Some polish.

* Fix `ArrayBuffer` to `Uint8Array` conversions.

* Fix aborting fetch leading to error and some polish.

* Replaced some `unwrap`s with `expect`s.

* Use `cfg_if` and `cfg_match` and do some polish.

* Proper scoping.

* Some fixes.

* Move fetch and reader services to different PR.

* Revert split.

* Fix CI builds (#877)

* Fix derive_props_test

* Move tests (#897) (#898)

* `web-sys` fetch service conversion (#867)

* Split implementation.

* Import global.

* Import global.

* Revert split.

* Make fetch available again.

* Revert "Revert split."

This reverts commit 6e3f101.

* Re-revert split.

* Some polish.

* Move to `wasm_bindgen_futures`.

* Switch to `thiserror`.

* wip

* Update src/services/fetch/web_sys.rs

Co-Authored-By: daxpedda <daxpedda@gmail.com>

* Some more polish.

Co-authored-by: Justin Starry <justin.m.starry@gmail.com>

* `web-sys` reader service conversion (#868)

* Split reader implementation.

* Revert split.

* Remove leftover files.

* Make reader available again.

* Revert "Revert split."

This reverts commit 8abdc9c.

* Revert "Remove leftover files."

This reverts commit 188c6eb.

* Re-revert split.

* Polish.

* Forgot some part.

* Some polish.

* Some polish.

* `web-sys` examples/tests conversion (#841)

* Fix examples/tests to work with `web_sys`.

* Update `StorageService` usage.

* Split `stdweb` and `web-sys` examples.

* Fixing the shell script.

* Trying to reset file permissions.

* Update to new reader API.

* Update to new fetch API.

* Update to new fetch API.

* Re-enable examples CI.

* Deleted duplicate example.

* Some fixes.

* Fix rand build.

* Fix spawning workers in combination with `wasm-bindgen`. (#901)

* Fix component rendering process (#913)

* wip

* Fix component rendering process

* Simplify yew-macro a bit (#902)

* yew-macro: Simplify Properties validation

* Fix most clippy warnings

* Fix clippy warnings (#912)

* Import Task trait in dashboard example

* Remove duplicate vtag tests

* Fix prevent_default() by non-passive (#958)

* Fix prevent_default() by non-passive

* Fix cargo fmt

* Remove `Option` from most services.

* Remove `Option` from resize service.

* Apply fetch changes.

* Apply reader service changes.

* Fix `node_refs` example.

* Remove web-sys travis branch

Co-authored-by: daxpedda <daxpedda@gmail.com>
Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>
Co-authored-by: Jet Li <jing.i.qin@icloud.com>
AlephAlpha pushed a commit to AlephAlpha/yew that referenced this pull request Feb 29, 2020
* Enable travis

* `web-sys` general conversion (yewstack#826)

* Moved patches from different PRs.

* Add bits & pieces and some services.

* Rename `stdweb` feature to `std_web`.

* Move tests and examples to different PR.

* Revert some `cargo_web` handling removal.

* Missed something.

* Implement `console_error_panic_hook`.

* Update Cargo.toml

Co-authored-by: Justin Starry <justin.m.starry@gmail.com>

* Move document creation to util convenience method (yewstack#855)

* `web-sys` listener conversion (yewstack#813)

* `web-sys` listener initial try.

* Improve macros?

* Remove generic from `EventListenerHandle`.

* Fix build.

* A cleaner solution?

* Even cleaner.

* Fix `build.rs`.

* Minor improvements.

* Following the yew toml style.

* Fixing visibility.

* Fix `rustfmt`.

* Add `web-sys` re-exports.

* Move general changes to different PR.

* Remove compat.

* Actually remove `compat.rs`.

* Rename `stdweb` feature to `std_web`.

* Move to gloo's `EventListener` and some polish.

* Remove outdated comment.

* Change `EventHandler` to be cancelled on drop.

* `web-sys` html conversion (yewstack#817)

* Converting all `html` parts.

* Format.

* Move general changes to different PR.

* Removed compat.

* Rename `stdweb` feature to `std_web`.

* Remove redudant function copy.

* Some polish.

* Move to gloo's `EventListener`.

* Replace `unwrap`s with `expect`s.

* `web-sys` agent conversion (yewstack#818)

* Converting `agent`.

* Remove wrong `cfg` in imports.

* Move general changes to different PR.

* Some optimisations.

* Rename `stdweb` feature to `std_web`.

* Fix `ArrayBuffer` to `Uint8Array` conversions.

* Add js module worker.

* Use `cfg-if`` and `cfg-match` to make things clearer.

* Fix `std_web` build.

* Add some polish.

* Add build guards for invalid build configs (yewstack#866)

* `web_sys` cfg conversion (yewstack#862)

* Use `cfg-if` and `cfg-match` and some polish.

* Mistakes were made.

* Missed line during rebasing.

* Mistakes were undone.

* Remove global.

* Remove part of `global!`.

* `web-sys` services conversion (yewstack#827)

* Convert `console`.

* Finish services.

* Some polish.

* Fix `ArrayBuffer` to `Uint8Array` conversions.

* Fix aborting fetch leading to error and some polish.

* Replaced some `unwrap`s with `expect`s.

* Use `cfg_if` and `cfg_match` and do some polish.

* Proper scoping.

* Some fixes.

* Move fetch and reader services to different PR.

* Revert split.

* Fix CI builds (yewstack#877)

* Fix derive_props_test

* Move tests (yewstack#897) (yewstack#898)

* `web-sys` fetch service conversion (yewstack#867)

* Split implementation.

* Import global.

* Import global.

* Revert split.

* Make fetch available again.

* Revert "Revert split."

This reverts commit 6e3f101.

* Re-revert split.

* Some polish.

* Move to `wasm_bindgen_futures`.

* Switch to `thiserror`.

* wip

* Update src/services/fetch/web_sys.rs

Co-Authored-By: daxpedda <daxpedda@gmail.com>

* Some more polish.

Co-authored-by: Justin Starry <justin.m.starry@gmail.com>

* `web-sys` reader service conversion (yewstack#868)

* Split reader implementation.

* Revert split.

* Remove leftover files.

* Make reader available again.

* Revert "Revert split."

This reverts commit 8abdc9c.

* Revert "Remove leftover files."

This reverts commit 188c6eb.

* Re-revert split.

* Polish.

* Forgot some part.

* Some polish.

* Some polish.

* `web-sys` examples/tests conversion (yewstack#841)

* Fix examples/tests to work with `web_sys`.

* Update `StorageService` usage.

* Split `stdweb` and `web-sys` examples.

* Fixing the shell script.

* Trying to reset file permissions.

* Update to new reader API.

* Update to new fetch API.

* Update to new fetch API.

* Re-enable examples CI.

* Deleted duplicate example.

* Some fixes.

* Fix rand build.

* Fix spawning workers in combination with `wasm-bindgen`. (yewstack#901)

* Fix component rendering process (yewstack#913)

* wip

* Fix component rendering process

* Simplify yew-macro a bit (yewstack#902)

* yew-macro: Simplify Properties validation

* Fix most clippy warnings

* Fix clippy warnings (yewstack#912)

* Import Task trait in dashboard example

* Remove duplicate vtag tests

* Fix prevent_default() by non-passive (yewstack#958)

* Fix prevent_default() by non-passive

* Fix cargo fmt

* Remove `Option` from most services.

* Remove `Option` from resize service.

* Apply fetch changes.

* Apply reader service changes.

* Fix `node_refs` example.

* Remove web-sys travis branch

Co-authored-by: daxpedda <daxpedda@gmail.com>
Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>
Co-authored-by: Jet Li <jing.i.qin@icloud.com>
jstarry added a commit that referenced this pull request Mar 1, 2020
* Properties 2.0

* Fix problem when passing a closure to prop_or_else

* Update test names

* Add support for building with web-sys (#961)

* Enable travis

* `web-sys` general conversion (#826)

* Moved patches from different PRs.

* Add bits & pieces and some services.

* Rename `stdweb` feature to `std_web`.

* Move tests and examples to different PR.

* Revert some `cargo_web` handling removal.

* Missed something.

* Implement `console_error_panic_hook`.

* Update Cargo.toml

Co-authored-by: Justin Starry <justin.m.starry@gmail.com>

* Move document creation to util convenience method (#855)

* `web-sys` listener conversion (#813)

* `web-sys` listener initial try.

* Improve macros?

* Remove generic from `EventListenerHandle`.

* Fix build.

* A cleaner solution?

* Even cleaner.

* Fix `build.rs`.

* Minor improvements.

* Following the yew toml style.

* Fixing visibility.

* Fix `rustfmt`.

* Add `web-sys` re-exports.

* Move general changes to different PR.

* Remove compat.

* Actually remove `compat.rs`.

* Rename `stdweb` feature to `std_web`.

* Move to gloo's `EventListener` and some polish.

* Remove outdated comment.

* Change `EventHandler` to be cancelled on drop.

* `web-sys` html conversion (#817)

* Converting all `html` parts.

* Format.

* Move general changes to different PR.

* Removed compat.

* Rename `stdweb` feature to `std_web`.

* Remove redudant function copy.

* Some polish.

* Move to gloo's `EventListener`.

* Replace `unwrap`s with `expect`s.

* `web-sys` agent conversion (#818)

* Converting `agent`.

* Remove wrong `cfg` in imports.

* Move general changes to different PR.

* Some optimisations.

* Rename `stdweb` feature to `std_web`.

* Fix `ArrayBuffer` to `Uint8Array` conversions.

* Add js module worker.

* Use `cfg-if`` and `cfg-match` to make things clearer.

* Fix `std_web` build.

* Add some polish.

* Add build guards for invalid build configs (#866)

* `web_sys` cfg conversion (#862)

* Use `cfg-if` and `cfg-match` and some polish.

* Mistakes were made.

* Missed line during rebasing.

* Mistakes were undone.

* Remove global.

* Remove part of `global!`.

* `web-sys` services conversion (#827)

* Convert `console`.

* Finish services.

* Some polish.

* Fix `ArrayBuffer` to `Uint8Array` conversions.

* Fix aborting fetch leading to error and some polish.

* Replaced some `unwrap`s with `expect`s.

* Use `cfg_if` and `cfg_match` and do some polish.

* Proper scoping.

* Some fixes.

* Move fetch and reader services to different PR.

* Revert split.

* Fix CI builds (#877)

* Fix derive_props_test

* Move tests (#897) (#898)

* `web-sys` fetch service conversion (#867)

* Split implementation.

* Import global.

* Import global.

* Revert split.

* Make fetch available again.

* Revert "Revert split."

This reverts commit 6e3f101.

* Re-revert split.

* Some polish.

* Move to `wasm_bindgen_futures`.

* Switch to `thiserror`.

* wip

* Update src/services/fetch/web_sys.rs

Co-Authored-By: daxpedda <daxpedda@gmail.com>

* Some more polish.

Co-authored-by: Justin Starry <justin.m.starry@gmail.com>

* `web-sys` reader service conversion (#868)

* Split reader implementation.

* Revert split.

* Remove leftover files.

* Make reader available again.

* Revert "Revert split."

This reverts commit 8abdc9c.

* Revert "Remove leftover files."

This reverts commit 188c6eb.

* Re-revert split.

* Polish.

* Forgot some part.

* Some polish.

* Some polish.

* `web-sys` examples/tests conversion (#841)

* Fix examples/tests to work with `web_sys`.

* Update `StorageService` usage.

* Split `stdweb` and `web-sys` examples.

* Fixing the shell script.

* Trying to reset file permissions.

* Update to new reader API.

* Update to new fetch API.

* Update to new fetch API.

* Re-enable examples CI.

* Deleted duplicate example.

* Some fixes.

* Fix rand build.

* Fix spawning workers in combination with `wasm-bindgen`. (#901)

* Fix component rendering process (#913)

* wip

* Fix component rendering process

* Simplify yew-macro a bit (#902)

* yew-macro: Simplify Properties validation

* Fix most clippy warnings

* Fix clippy warnings (#912)

* Import Task trait in dashboard example

* Remove duplicate vtag tests

* Fix prevent_default() by non-passive (#958)

* Fix prevent_default() by non-passive

* Fix cargo fmt

* Remove `Option` from most services.

* Remove `Option` from resize service.

* Apply fetch changes.

* Apply reader service changes.

* Fix `node_refs` example.

* Remove web-sys travis branch

Co-authored-by: daxpedda <daxpedda@gmail.com>
Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>
Co-authored-by: Jet Li <jing.i.qin@icloud.com>

* Fix vtag test warning (#978)

* Clean up exported apis and doc visibility (#977)

* Clean up exported apis and doc visibility

* Remove unused ScopeHolder

* Change ComponentLink to alias of Scope

* cargo fmt

* update new examples to Properties 2.0

* Fix a mistake when resolving conflicts

* Remove an outdated hack.

Co-authored-by: Justin Starry <justin.m.starry@gmail.com>
Co-authored-by: daxpedda <daxpedda@gmail.com>
Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>
Co-authored-by: Jet Li <jing.i.qin@icloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants