purescript-web/purescript-web-html

Foreign.Object instead of Foreign?

Closed this issue · 1 comments

Should this use Foreign.Object instead of Foreign?

foreign import pushState :: Foreign -> DocumentTitle -> URL -> History -> Effect Unit

The purescript-foreign repo is more for when we're reading plain JavaScript objects, and the purescript-foreign-object repo is more for when we're writing plain JavaScript objects. This is more like the latter situation, from the perspective of the purescript-web-html user API.

Like, I want to pass Foreign.Object.empty as the first argument to pusState, but there is no empty in purescript-foreign. So I’m going to pass unsafeToForeign {}.

And similarly for everywhere else in this repo.

garyb commented

I missed this issue when it was opened.

I understand where you're coming from, but think the current definition is right as it is. pushState doesn't accept an object for its state object, it accepts "any serializable value", which would include literals.

I dislike the fact that Foreign is in there at all really, but that's just because I dislike Foreign in general 😄 but I don't think there is a better option either - I do still prefer it over making it "any" by just having the argument as a type variable, because at least you have to think about what you're putting in there.

It sounds like adding something like an emptyObject to Foreign would be useful though!