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

Existing Effects & Refs #196

Merged
merged 10 commits into from
Jun 30, 2022
Merged

Existing Effects & Refs #196

merged 10 commits into from
Jun 30, 2022

Conversation

JRJurman
Copy link
Member

@JRJurman JRJurman commented Jun 26, 2022

Summary

This PR makes updates to how useEffect works, mostly in prep for #173

Fixes #130
Fixes #166
Fixes #112

Changes

Additional Changes

  • changed top level element to be <tram-one> rather than <div>, this is more clear and obvious, and won't cause formatting issues (since <tram-one> should be undecorated).
  • make the pattern parameter for useUrlParams optional (the underlying library has a default value here, so no parameter should be required).
  • Some underlying types were more explicitly defined
    • This was required to make dealing with the ref parameter in useEffect much easier (and not require wrapping in a cast to as unknown).

Version Bump: Minor

This PR adds new functionality, that should not be breaking in any previously declared way. It's not required by any means for existing projects, so minor feels like the most appropriate here.

Checklist

  • PR Summary
  • PR Annotations
  • Tests
  • Version Bump

@@ -13,6 +13,6 @@ export default (component: RootTramOneComponent, container: Container) => {

// this sadly needs to be wrapped in some element so we can process effects
// otherwise the root node will not have effects applied on it
const renderedApp = html`<div><app /></div>`;
const renderedApp = html`<tram-one><app /></tram-one>`;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the UI, this appears like the following:
image

This is better than <div>, because we won't inherit any unexpected styles or formatting.

@@ -17,7 +17,7 @@ import { UrlMatchResults } from './types';
*
* @returns object with a `matches` key, and (if it matched) path and query parameters
*/
export default (pattern: string): UrlMatchResults => {
export default (pattern?: string): UrlMatchResults => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should have always been optional! This better matches the interface of the underlying library.

@@ -55,7 +55,7 @@ const processTramTags = (node: Node | TramOneElement) => {
const effectReaction = observe(() => {
// verify that cleanup is a function before calling it (in case it was a promise)
if (typeof cleanup === 'function') cleanup();
cleanup = effect();
cleanup = effect(node);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what is required for allowing us to accept ref as a parameter for useEffect - we pass the node we are processing back into the effect it defined!

Comment on lines +62 to +63
// cleanup effects will be populated when new effects are processed
tagResult[TRAM_TAG_CLEANUP_EFFECTS] = [];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no reason this should have been populated by the existing new effects before...

Comment on lines +111 to +113
export type TramOneHTMLElement = TramOneElement & HTMLElement;
export type TramOneSVGElement = TramOneElement & SVGElement;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new type definitions, because TramOneElement is too generic, and in reality (right now) it's always an HTMLElement or SVGElement.

If we ever expose registerDOM, people should be able to make their own TramOneElement definitions (which shouldn't be too hard to do).

Copy link
Contributor

@chtinahow chtinahow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditional approval based on a test for those merged elements 👍

@JRJurman JRJurman merged commit 1d72174 into master Jun 30, 2022
@JRJurman JRJurman deleted the process-existing-effects branch June 30, 2022 04:18
@JRJurman JRJurman restored the process-existing-effects branch July 1, 2022 13:17
@JRJurman JRJurman deleted the process-existing-effects branch July 1, 2022 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants