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

RouterEventType is no longer exported? #44

Closed
aigr opened this issue Sep 24, 2019 · 11 comments
Closed

RouterEventType is no longer exported? #44

aigr opened this issue Sep 24, 2019 · 11 comments

Comments

@aigr
Copy link

aigr commented Sep 24, 2019

Previsouly you could do a

import { RouterEventType } from 'crayon/types'

This no longer works. Where is it exported now?

@aigr
Copy link
Author

aigr commented Sep 24, 2019

A work-around might be to do

if (event.type === 'ROUTER_END') {

Instead of

if (event.type === RouterEventType.ProgressEnd) {

@aigr
Copy link
Author

aigr commented Sep 24, 2019

But other things have changed as well.

If I have something like

nav.path('/browse/:cname', (req, res) => {
  const sub = nav.events.subscribe(event => {
    // if (event.type === RouterEventType.ProgressEnd) {
    if (event.type === 'ROUTER_END') {
      res.mount(Collection, { req, nav })
    }
  })
  res.onLeave(() => sub.unsubscribe())
})

Then previously a call to nav.navigate('/browse/foo'), while "being" on '/browse/bar' worked out. Now I need to click links twice for it to flip.

@alshdavid
Copy link
Owner

Hey thanks for your issue.
I'm releasing an update now to re-expose the RouterEventType.

image

Going to try to recreate your second issue to see what's going on there

@alshdavid
Copy link
Owner

alshdavid commented Sep 25, 2019

Export should work as of version 4.1.5
Will need to investigate further on your other issue

@aigr
Copy link
Author

aigr commented Sep 25, 2019

Hmm. Perhaps I'm doing something wrong, but it doesn't seem to work for me

$ jq  '.dependencies.crayon.version' package-lock.json
"4.1.5"

And then

$ npm run build
...
[!] Error: 'RouterEventType' is not exported by node_modules/crayon/dist/index.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
svelte/main.js (3:17)
3: import crayon, { RouterEventType } from 'crayon'
                    ^
Error: 'RouterEventType' is not exported by node_modules/crayon/dist/index.js

@alshdavid
Copy link
Owner

It seems good here:

JavaScript:
https://stackblitz.com/edit/typescript-akyrxk

TypeScript:
https://stackblitz.com/edit/js-7yh9tp

Did you try uninstalling/installing it again?

npm uninstall --save crayon
npm install -save crayon

@alshdavid
Copy link
Owner

I have added the following test to the latest current version:

it('Should ', async (done) => {
  const window = new MockWindow() as any
  const app = create('test-router', window)
  let hasClicked = false

  app.path('/browse/:cname', (req, res) => {
    const sub = app.events.subscribe(async event => {
      if (event.type !== RouterEventType.ProgressEnd) {
        return
      }
      if (hasClicked == true) {
        done()
        return
      }
      hasClicked = true
      await app.navigate('/browse/b')
    })
    res.onLeave(() => sub.unsubscribe())
  })

  await app.load()
  await app.navigate('/browse/a')
})

Does that cover your use case? If not, could you set up a code sandbox illustrating your case?

@aigr
Copy link
Author

aigr commented Oct 2, 2019

Still doesn't work for me locally, but that must surely be some kind of mistake on my part. It seems to work out well elsewhere. 😄

W.r.t to my second problems, where links have to pressed twice to change, I've made a minimalistic example of it at https://codesandbox.io/s/sweet-taussig-2q3wb.

You go "Home", press "foo", then keep pressing the links for "next".

(I've somehow messed up the transitions, but that's another story)

@alshdavid
Copy link
Owner

Thanks for taking the time to put together that sandbox! I'm working on it now.

@alshdavid
Copy link
Owner

Just a quick update on this.

app.events.subscribe(event => {
  if (event.type !== "ROUTER_END") {
    return
  }
  console.log(window.location.pathname)
  console.log(req.params.name) 
});

req.params.name lags behind window.location.pathname
So It seems like I'm not updating the request at the right time.

Looks like the RouterEventType value is available in TypeScript, but not in JavaScript. Looking into that too.

@alshdavid
Copy link
Owner

alshdavid commented Dec 2, 2019

RouterEventType is now exported on the default crayon export

You can check out this sandbox
https://codesandbox.io/s/svelte-khjjw?fontsize=14&hidenavigation=1&theme=dark

I'll be enhancing the documentation soon, but for now to access RouterEventType do the following:

import crayon from 'crayon'

console.log(crayon.RouterEventType.ProgressStart)

Let me know if you have any issues, otherwise I'll close this issue for now

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

No branches or pull requests

2 participants