easystarjs icon indicating copy to clipboard operation
easystarjs copied to clipboard

Return result directly from findPath with enableSync()

Open PSeitz opened this issue 6 years ago • 7 comments

PSeitz avatar Oct 08 '17 07:10 PSeitz

I appreciate the change, but I'm not sure I will merge this. I think I prefer the API to be consistent in both the sync and async cases even if it's a little less convenient.

One option would be to follow the node standard modules convention in creating a findPathSync which has this behavior, but it seems unnecessary given we already have the existing configuration option, and may just be more confusion than it's worth.

prettymuchbryce avatar Oct 08 '17 16:10 prettymuchbryce

From the API perspective sync calls usually return values, only async operations require functions callbacks, but I agree both mangled in this function is not great.

A new function may be the best way. I would remove enableSync as configuration and just provide findPathSync since enableSync and a callback is confusing.

PSeitz avatar Oct 09 '17 11:10 PSeitz

I think it makes sense to add the findPathSync and deprecate the enableSync option, but we can't just remove it outright otherwise we will break backwards compatibility.

prettymuchbryce avatar Oct 12 '17 15:10 prettymuchbryce

@prettymuchbryce Firstly, thank you for creating this great library, really impressive work.

I agree that the implementation of findPathSync would be a valuable iteration to the current enableSync method. I'm in a situation where I need to manage multiple co-dependant paths, so right now (although possible) the thought of handling them asynchronously and dealing potential race conditions (or having to manage synchronous callbacks) is putting me off.

Is there any update on this PR? It'd be great to get this in master. If there's anything I can do to help, I'm more than happy to contribute.

mikedevelops avatar Apr 11 '18 07:04 mikedevelops

@mikedevelops I understand your concerns. I think the proposal in this PR makes a lot of sense. If you are interested in contributing, I think this would be a good candidate for a first PR.

This PR is nearly completed. In my mind I see only a few remaining tasks.

  1. Restore the enableSync option that was deleted as part of this PR. We can't remove it, because we want to retain backwards compatibility so we don't break people's projects.
  2. Write some unit tests for findPathSync.
  3. Optional, but I'm noticing we don't currently have tests for enableSync, so writing a test or two for that to ensure it still works as expected after the change would be preferred.

I'm happy to answer any questions in this thread.

prettymuchbryce avatar Apr 11 '18 08:04 prettymuchbryce

Okay sounds great @prettymuchbryce, I'll aim to get that done by the weekend 😄

mikedevelops avatar Apr 11 '18 08:04 mikedevelops

@prettymuchbryce It seemed easier to create a separate PR for this, I've added findPathSync method and left all the existing functionality untouched to maintain backwards compatibility. I added those enableSync tests also 👍 .

It's open here (https://github.com/prettymuchbryce/easystarjs/pull/62) and ready for review.

mikedevelops avatar Apr 11 '18 10:04 mikedevelops