Skip to content

Add Node driver#1

Merged
JordanMartinez merged 27 commits into
purescript-contrib:mainfrom
JordanMartinez:add-node-driver
Apr 1, 2022
Merged

Add Node driver#1
JordanMartinez merged 27 commits into
purescript-contrib:mainfrom
JordanMartinez:add-node-driver

Conversation

@JordanMartinez

Copy link
Copy Markdown
Contributor

Description of the change

Copies over Affjax.purs from purescript-affjax and updates the _ajax FFI to be Node specific via the xhr2 library. See purescript-contrib/purescript-affjax#171

Also updates this library to only compile on 0.15.0.


Checklist:

  • Added the change to the changelog's "Unreleased" section with a link to this PR and your username
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation in the README and/or documentation directory
  • Added a test for the contribution (if applicable)

@JordanMartinez

Copy link
Copy Markdown
Contributor Author

Since affjax doesn't expose a driver arg yet, CI will fail to build.

@JordanMartinez JordanMartinez changed the base branch from master to main March 29, 2022 16:15
, delete_
, patch
, patch_
) where

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We may as well export the driver too (so, everything I guess? 😄) - that way it can be passed in explicitly to the functions in -affjax if someone wants to / if something is added there but this isn't updated yet / etc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm hesitant about doing that because someone might try to use both the node and web drivers in the same code. By not exporting it, it forces them to use this API as is.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Any updates on this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I was just revisiting this stuff now actually :) will post more thoughts shortly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think that exposing the driver will make it more or less likely that both dependencies end up in a project - it seems just as likely they'd try to import functions from both Affjax.Driver.Node and Affjax.Driver.Web to me?

Exposing the driver also enables extra capabilities - like my suggestion for allowing people to hook into the XHR object in the web case so they can attach event listeners or whatever, by having a method of constructing the driver(s) with extra arguments.

It also might actually make sense for some projects to have both drivers included, if the project has multiple entry points. They could acquire the driver value from a Reader so that part of the codebase can make requests in either context.

I've actually been in a situation exactly like this, where we had an API implementation that was shared between test code and the UI, where the test code would make API calls to set things up for automated browser tests to run against, and then clean up afterwards. Without the ability to pick the driver from the Reader, it would have meant implementing two entirely different types for whether it was the tests or the UI wanting to call the API, and the implementations would have been identical apart from having different imports.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah good points! Ok, I'll export it then.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread src/Affjax/Driver/Node.purs Outdated
Comment thread .github/workflows/ci.yml
Comment on lines -47 to +54
- name: Build the project
run: npm run build
# - name: Build the project
# run: npm run build

- name: Run tests
run: npm run test
# - name: Run tests
# run: npm run test

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I assume this is intentional in both the driver projects just now, until the core library PR is merged?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's intentional due to it calling spago test, which doesn't currently work due to the ESM changes.

@JordanMartinez JordanMartinez merged commit 06f8408 into purescript-contrib:main Apr 1, 2022
@JordanMartinez JordanMartinez deleted the add-node-driver branch April 1, 2022 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants