visionmedia / page.js

Micro client-side router inspired by the Express router
http://visionmedia.github.com/page.js
7.67k stars 687 forks source link

Add page.create() to allow multiple pages #461

Closed matthewp closed 5 years ago

matthewp commented 6 years ago

This adds a new feature, page.create() that allows for there to be multiple pages. Calling page.create(options) create a new page function that behaves just like the global page. It contains its own internal state, options, and event handlers. You can target the page to another window, like an iframe or a popup, if you want.

var newPage = page.create({
  window: someIframe.contentWindow
});

The main reason for adding this feature was to clean up or testing infrastructure. Numerous things had to be done in the past to make sure each test was cleanly in isolation. That stuff is no longer necessary now that we can just create a new page instance for each test.

Closes #13

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.2%) to 89.496% when pulling 263f93859808e47d16e3cfe8f8a7bd2809d499d1 on mult2 into cc40bc4c8b7986f1f8013efaf81c87138ca84718 on master.

paulocoghi commented 6 years ago

Just a question. Is it still possible to use page.js without page.create({...}), just by calling page()?

matthewp commented 6 years ago

@paulocoghi Yeah, this doesn't break any existing usage at all. It's a refactor so that instead of having the global state it's all contained within an instance. So there's still the default instance that is exported and covers 99% of everyone's needs. No worries, wouldn't ever want to get away from page.js' ease of use! :)

matthewp commented 6 years ago

Looks like the refactor decreased test coverage by 2.5%! Since no tests were removed I'm guessing that it exposed some stuff that wasn't being tested before. Think I can increase this by testing the new .configure() and by testing the unhandled function.

litinskii commented 6 years ago

Hi to all. Any updates about this improvement are it going to be in next release ? Thanks.

matthewp commented 6 years ago

Just need to find the time to fix the test coverage.

matthewp commented 5 years ago

Finally!