From 4c65452dd22f2b40b42af7d203ddabd2d2562006 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Augustin=20=C5=A0ulc?= Date: Sat, 18 Feb 2023 19:15:27 +0100 Subject: [PATCH] Added tanstack/router --- examples/navigation/package.json | 2 +- .../src/customers/customersViewModel.ts | 22 +- examples/navigation/src/home/homeView.tsx | 31 ++- examples/navigation/src/home/homeViewModel.ts | 1 - .../src/invoices/invoiceDetailViewModel.ts | 10 +- .../navigation/src/invoices/invoicesView.tsx | 2 +- .../src/invoices/invoicesViewModel.ts | 14 +- examples/navigation/src/main.tsx | 69 +++--- examples/todolist/package.json | 2 +- examples/todolist/src/list/Footer.tsx | 6 +- .../todolist/src/list/todoListViewModel.ts | 27 ++- examples/todolist/src/main.tsx | 29 ++- packages/views/package.json | 1 - packages/views/src/binding/useBinding.tsx | 6 +- packages/views/src/index.ts | 1 - packages/views/src/router/RouteView.tsx | 25 --- packages/views/src/router/router.tsx | 199 +++++++++++++++--- packages/views/src/router/types.ts | 27 ++- .../src/router/viewModelLifecycleManager.ts | 102 +++++++++ yarn.lock | 15 -- 20 files changed, 424 insertions(+), 167 deletions(-) delete mode 100644 packages/views/src/router/RouteView.tsx create mode 100644 packages/views/src/router/viewModelLifecycleManager.ts diff --git a/examples/navigation/package.json b/examples/navigation/package.json index cfd0bb8..e9a06f1 100644 --- a/examples/navigation/package.json +++ b/examples/navigation/package.json @@ -10,7 +10,7 @@ }, "dependencies": { "@frui.ts/views": "^999.0.0", - "@tanstack/react-location": "^3.7.4", + "@tanstack/react-router": "^0.0.1-beta.82", "mobx": "6.7.0", "mobx-react-lite": "3", "react": "^18.2.0", diff --git a/examples/navigation/src/customers/customersViewModel.ts b/examples/navigation/src/customers/customersViewModel.ts index 4487273..5bbc24d 100644 --- a/examples/navigation/src/customers/customersViewModel.ts +++ b/examples/navigation/src/customers/customersViewModel.ts @@ -1,7 +1,9 @@ +import type { IViewModel, NavigationContext, NoParams } from "@frui.ts/views"; import { makeObservable, observable, runInAction } from "mobx"; -import type { IViewModel, SearchType } from "@frui.ts/views"; -export default class CustomersViewModel implements IViewModel { +type SearchScheme = { name?: string }; + +export default class CustomersViewModel implements IViewModel { @observable search?: string; @@ -9,9 +11,21 @@ export default class CustomersViewModel implements IViewModel { makeObservable(this); } - onNavigate(search: SearchType) { + onNavigate({ search }: NavigationContext) { + console.log("customers navigate", search); + runInAction(() => { - this.search = search.name as string; + this.search = search.name; }); } + + onDeactivate(context: NavigationContext) { + console.log("customers deactivate"); + } + + static validateSearch(search: Record) { + return { + name: search.name as string | undefined, + }; + } } diff --git a/examples/navigation/src/home/homeView.tsx b/examples/navigation/src/home/homeView.tsx index 5127fdb..20b4998 100644 --- a/examples/navigation/src/home/homeView.tsx +++ b/examples/navigation/src/home/homeView.tsx @@ -1,34 +1,51 @@ import { registerViewComponent } from "@frui.ts/views"; -import { Link, Outlet } from "@tanstack/react-location"; +import { Link, Outlet } from "@tanstack/react-router"; import { Observer } from "mobx-react-lite"; import React from "react"; import HomeViewModel from "./homeViewModel"; export const HomeView = registerViewComponent(HomeViewModel, vm => { + const linkProps = { + activeProps: { style: { color: "red" } }, + activeOptions: { + exact: true, + }, + }; + return (