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

Tabris.js router #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Tabris.js router #34

wants to merge 2 commits into from

Conversation

ahmadov
Copy link

@ahmadov ahmadov commented Mar 6, 2020

No description provided.


export abstract class Route {
page: RoutePage;
options: RouteOptions = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this nesting? Why not directly on Route?


private _navigationView: NavigationView;
private _routes: ListLike<RouterConfig>;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No empty line


export type HistoryItem = { route: string, payload?: any };

export class RouterHistory<T extends HistoryItem = HistoryItem> extends ListLikeObvserver<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An observer must never modify the obversvee. These methods should be router internals, or RouterHistory class it wraps, not extend the observer.

export class RouterHistory<T extends HistoryItem = HistoryItem> extends ListLikeObvserver<T> {

public push(item: T) {
const source = Array.from(this.source);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would replace the source even if it's a list. I'd rather deal with this using instanceof

}

set history(value: ListLike<HistoryItem>) {
if (this._routerHistoryObserver.source === value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary optimization.

return this._routerHistoryObserver.source;
}

set routes(value: ListLike<RouterConfig>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Routes should be resolved via DI on demand (when they are needed). No property.

@Injectable('myRoute')
class MyRoute extends Route {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We COULD enable another way to give routes IN ADDITION, but I dont think we should allow removing/replacing routes after the router was created.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we resolve/create the object via class name? I'm trying to find the alternative ways to use the DI.

}

protected _handleHistoryChange = ({deleteCount, items}: Mutation<ItemType>) => {
if (deleteCount > items.length) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you don't know where in the history the items were deleted. This assumes it's at the end. It also doesn't handle replacement.

private _routerHistoryObserver: RouterHistory;
private _routerMatcher: RouterMatcher;

constructor({navigationView, routers, defaultRoute, history} : RouterProperties) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm.... do we need a default route? What's the use-case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's useful to navigate to the initial route


private _appendRoute(route: Route, payload?: any) {
if (route.page.onPayload && typeof route.page.onPayload === 'function') {
route.page.onPayload(payload);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "payload" should be given to the route, not the page. Also, the entire item should be given so the router knows which kind of payload to expect. Also, it should just be a property like "item" or "historyItem", not a method with a name that sounds like listener.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought "payload" would be uninteresting to a route because, only the page reacts payload and will do UI changes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the current implementation works as follows:

  1. create all routes and pages (UI).
  2. each page does UI changes based on the payload (that's why I named 'onPayload'). Even, the same page can use different payloads.

I've implemented without much investigation, maybe there are more robust alternatives to achieve the same behaviour.

route.page.onPayload(payload);
}
this._navigationView.append(route.page);
this._navigationView.drawerActionVisible = route.options.enableDrawer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these two featues are a bit advanced for the first commit.

@tbuschto tbuschto force-pushed the master branch 2 times, most recently from 36f18dc to e90fd70 Compare March 18, 2020 18:42
@ahmadov ahmadov force-pushed the tabris-router branch 2 times, most recently from 3e3ebfe to 3bd65a5 Compare April 9, 2020 12:30
@ahmadov ahmadov force-pushed the tabris-router branch 2 times, most recently from 44aac30 to 57e82ea Compare April 9, 2020 12:38
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

Successfully merging this pull request may close these issues.

2 participants