-
Notifications
You must be signed in to change notification settings - Fork 3
Page.js
Page.js manage all our ajax requests.
client/main.js is where the routes and handlers for these routes are defined. When the browser attempt to access a url Page.js will try to catch the url and execute the handler linked to this url:
page('/search/:type', load, render, listeners);
here the url /search/:type will execute in order the load render and listeners callbacks.
Even when the page is loaded normally (without any ajax request) page.js will try to match the url and call the callback link of the route. This will send this time another ajax request
The variable ctx.isIntialRender determine if a page has been loaded for the first time or not. This allow to trigger the ajax requests only when a page has already been loaded and solve the problem of request a page twice, on a normal loading and when page.js recognise the route.
Search route (clien/routes/search.js)
page('/search', load, render, listeners);
page('/search/:type', load, render, listeners);
The :type parameter match people, objects or documents
The role of the load function is to send a api type request to the server. The response object will be then converted in an html response object by reusing the transform function. There are two main transformation and object to buid from the html url received by load:
- Create a queryParams object which will be used to create the html object for Handlebars
- Create a json type request url