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

Cleanup #256

Closed
folknor opened this issue Jul 7, 2021 · 6 comments
Closed

Cleanup #256

folknor opened this issue Jul 7, 2021 · 6 comments
Labels
bug Something isn't working

Comments

@folknor
Copy link

folknor commented Jul 7, 2021

No problem here, I am just puzzled by it:

  1. start.js runs
  2. await getData(ctx)
  3. findMatches(queryVal, ctx)
  4. if (ctx.resultsList) render(ctx)

In step 2, ctx.feedback is set to data.src, and then in step 3, ctx.feedback is set to ctx.feedback = { query, matches, results }.

In between those, I can not see that ctx.feedback is read anywhere?

Can this line in dataController.js

ctx.feedback = data.store = typeof data.src === "function" ? await data.src(query) : data.src;

be changed to

data.store = typeof data.src === "function" ? await data.src(query) : data.src;

Or what am I not seeing?

@folknor folknor added the bug Something isn't working label Jul 7, 2021
@folknor
Copy link
Author

folknor commented Jul 7, 2021

Also another question, because I don't know JS that well. Does this code in dataController.js change the value of ctx.query?

  let { input, query, data } = ctx;
  query = query ? query(input.value) : input.value;

Should it be

 const { input, query, data } = ctx;

 if (data.cache && data.store) return;

 const queryVal = query ? query(input.value) : input.value;

I don't code in JS that much so I'm not always sure which values are passed by reference and by value.

I could have googled this before asking, but it was easier to just mention it :-)

@folknor
Copy link
Author

folknor commented Jul 7, 2021

There's 3 places in the code where you do let { ... } = ctx instead of const { ... } = ctx.

@folknor
Copy link
Author

folknor commented Jul 7, 2021

Obviously start.js would have to change if (ctx.feedback instanceof Error) return; to if (ctx.data.store instanceof Error) return; as well along with comment 1.

@TarekRaafat
Copy link
Owner

TarekRaafat commented Jul 7, 2021

No problem here, I am just puzzled by it:

  1. start.js runs
  2. await getData(ctx)
  3. findMatches(queryVal, ctx)
  4. if (ctx.resultsList) render(ctx)

In step 2, ctx.feedback is set to data.src, and then in step 3, ctx.feedback is set to ctx.feedback = { query, matches, results }.

In between those, I can not see that ctx.feedback is read anywhere?

Can this line in dataController.js

ctx.feedback = data.store = typeof data.src === "function" ? await data.src(query) : data.src;

be changed to

data.store = typeof data.src === "function" ? await data.src(query) : data.src;

Or what am I not seeing?

Answering your first question, the ctx.feedback is read through the eventEmitter detail.

Your second question, if we applied the proposed change this means that you won't be able to catch the data fetching errors through the eventEmitter.

@TarekRaafat
Copy link
Owner

There's 3 places in the code where you do let { ... } = ctx instead of const { ... } = ctx.

Thanks for that, I've updated them all in v10.2.4 👍🏻

@folknor
Copy link
Author

folknor commented Jul 7, 2021

Ah I didn't see that :-) Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants