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

feat(form-data): allow passing a form to FormData #26

Merged
merged 13 commits into from
Dec 2, 2022
Merged

Conversation

mcansh
Copy link
Collaborator

@mcansh mcansh commented Nov 30, 2022

No description provided.

Signed-off-by: Logan McAnsh <logan@mcan.sh>
Signed-off-by: Logan McAnsh <logan@mcan.sh>
@changeset-bot
Copy link

changeset-bot bot commented Nov 30, 2022

🦋 Changeset detected

Latest commit: 31a3c7d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@remix-run/web-form-data Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Signed-off-by: Logan McAnsh <logan@mcan.sh>
* @param {Element} element
* @returns {element is HTMLSelectElement}
*/
function isSelectElement(element) {
Copy link
Member

Choose a reason for hiding this comment

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

these are only used once, might as well inline them?

Copy link
Collaborator Author

@mcansh mcansh Nov 30, 2022

Choose a reason for hiding this comment

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

doing so loses out on some type checking as it doesn't do a element is HTMLSelectElement assertion anymore Property 'value' does not exist on type 'Element'. :/

Copy link
Member

Choose a reason for hiding this comment

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

TYPESCRIPT!!!!!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i felt a jsdoc to typescript migration was a little 🤏 outside of the scope of this PR haha

Signed-off-by: Logan McAnsh <logan@mcan.sh>
Signed-off-by: Logan McAnsh <logan@mcan.sh>
Signed-off-by: Logan McAnsh <logan@mcan.sh>
Signed-off-by: Logan McAnsh <logan@mcan.sh>
@@ -259,4 +259,28 @@ export const test = (test) => {
"rename.md"
);
});

test("Should allow passing a form element", () => {
Copy link
Member

Choose a reason for hiding this comment

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

Let's drop the jsdom dev dependency and just make our own mock HTMLFormElement that's got all the right methods/getters/etc. that we use.

@@ -7,7 +7,7 @@ import { assert } from "./test.js";
* @param {import('./test').Test} test
*/
export const test = (test) => {
test("test baisc", async () => {
Copy link
Member

Choose a reason for hiding this comment

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

BAISC!

Signed-off-by: Logan McAnsh <logan@mcan.sh>
checked: true,
}
]
};
Copy link
Member

Choose a reason for hiding this comment

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

We need Object.prototype.toString.call(value) === "[object HTMLFormElement]"; to evaluate correctly.

class FakeForm {
  get [Symbol.toStringTag]() {
    return "HTMLFormElement";
  }
  
  get elements() {
    return [/* ... */]
  }

  get id() {
    return "my-form"
  }
}

let form = new FakeForm();

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag

Signed-off-by: Logan McAnsh <logan@mcan.sh>
Signed-off-by: Logan McAnsh <logan@mcan.sh>
Signed-off-by: Logan McAnsh <logan@mcan.sh>
@mcansh mcansh linked an issue Dec 1, 2022 that may be closed by this pull request
4 tasks
@mcansh mcansh removed a link to an issue Dec 1, 2022
4 tasks
@ryanflorence ryanflorence merged commit 090ea15 into main Dec 2, 2022
@mcansh mcansh deleted the logan/formdata branch December 2, 2022 22:57
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