Skip to content

Commit

Permalink
fix optional arguments bug
Browse files Browse the repository at this point in the history
  • Loading branch information
b-rad-c committed Apr 6, 2024
1 parent 048e3fb commit 7e5d20b
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 37 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ This lightweight (~215 lines) VanJS addon adds the following features:
- pass additional context data such as a prefetched data or other configuration to route component
- TypeScript support

# Beta
### Official release

🚨 Van Cone is in Beta 🚨
Van Cone has reached version 1.0.0 and is no longer in beta.

Van Cone is close but not quite out of beta, so use with your own caution.

# Overview

Expand Down Expand Up @@ -95,6 +94,10 @@ Example HTML:

# Changelog

**1.0.0**
- fix issue #4 - argument for `navigate` and `pushHistory` functions
- Van Cone is out of beta and is API stable

**0.0.8**
- fix type definitions for `navigate` and `pushHistory` functions

Expand Down
4 changes: 4 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Van Cone has only one exported function [`createCone`](./api-reference.md#create
### TypeScript
- Supported! 🥳

### Official release

Van Cone has reached version 1.0.0 and is no longer in beta! 🥳

# Your first Van Cone App

Init your npm project
Expand Down
14 changes: 7 additions & 7 deletions examples/component-routing/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/component-routing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test-report": "npx playwright show-report"
},
"dependencies": {
"van-cone": "^0.0.8",
"van-cone": "^1.0.0",
"vanjs-core": "^1.2.7"
},
"devDependencies": {
Expand Down
14 changes: 11 additions & 3 deletions examples/component-routing/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import createCone from 'van-cone'
import van from 'vanjs-core'
const { div, span, hr } = van.tags
const { div, span, hr, button, br } = van.tags

// define page components
const homePage = div('Home Page')
const homePage = div(
'Home Page',
br(),
// these buttons exists to test the navigation functions
button({onclick: () => navigate('default')}, 'test navigation function - wo options'), br(),
button({onclick: () => navigate('default', {query: {'x': '1', 'y': '2'}})}, 'test navigation function - w options'), br(),
button({onclick: () => pushHistory('default')}, 'test pushHistory function - wo options'), br(),
button({onclick: () => pushHistory('default', {query: {'x': '1', 'y': '2'}})}, 'test pushHistory function - w options')
)
const vanJSElementPage = div('Van JS Element Page')
const functionPage = () => div('Function Page')

Expand All @@ -17,7 +25,7 @@ const fromStringPage = '<div>From String Page</div>'

// create the spa object
const routerElement = div({ id: 'layout' })
const { link, route } = createCone({routerElement: routerElement})
const { link, route, navigate, pushHistory } = createCone({routerElement: routerElement})

route('home', '/', homePage)
route('van-element', '/van-element', vanJSElementPage)
Expand Down
20 changes: 20 additions & 0 deletions examples/component-routing/tests/component-routing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,24 @@ test('test', async ({ page }) => {

await page.getByRole('link', { name: 'Non Default String' }).click();
await expect(page.locator('#layout')).toContainText('Non Default String Page');
});

test('test navigate function', async ({ page }) => {
await page.goto('http://localhost:5173');
await page.getByRole('button', { name: 'test navigation function - wo options' }).click();
await expect(page.locator('#layout')).toContainText('Default Export Page');

await page.goto('http://localhost:5173');
await page.getByRole('button', { name: 'test navigation function - w options' }).click();
await expect(page.locator('#layout')).toContainText('Default Export Page');
});

test('test pushHistory function', async ({ page }) => {
await page.goto('http://localhost:5173');
await page.getByRole('button', { name: 'test pushHistory function - wo options' }).click();
await expect(page.locator('#layout')).toContainText('Home Page');

await page.goto('http://localhost:5173');
await page.getByRole('button', { name: 'test pushHistory function - w options' }).click();
await expect(page.locator('#layout')).toContainText('Home Page');
});
14 changes: 7 additions & 7 deletions examples/hello-world/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test-report": "npx playwright show-report"
},
"dependencies": {
"van-cone": "^0.0.8",
"van-cone": "^1.0.0",
"vanjs-core": "^1.2.7"
},
"devDependencies": {
Expand Down
14 changes: 7 additions & 7 deletions examples/spa-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/spa-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"vite-bundle-visualizer": "^0.7.0"
},
"dependencies": {
"van-cone": "^0.0.8",
"van-cone": "^1.0.0",
"vanjs-core": "^1.2.7"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "van-cone",
"version": "0.0.8",
"version": "1.0.0",
"description": "a lightweight package providing basic SPA such as routing, history and navigation functionality for VanJS applications",
"homepage": "https://medium-tech.github.io/van-cone-website",
"repository": {
Expand Down
8 changes: 4 additions & 4 deletions src/spa.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ declare type RouteHandlerProps = {
};

declare type NavigateOptions = {
params: RouteParams;
query: QueryParams;
navState: NavState;
context: RouterContext;
params?: RouteParams;
query?: QueryParams;
navState?: NavState;
context?: RouterContext;
};

declare type RouterConfig = {
Expand Down
5 changes: 3 additions & 2 deletions src/spa.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,19 @@ function createCone(coneConfig) {

// navigation functions
const navigate = (routeName, options) => {
const { params, query, navState, context } = options
const { params, query, navState, context, dispatch } = options || {}
const url = router.navUrl(routeName, params, query)

if (typeof navState !== 'undefined') setNavState(navState)
history.pushState(getNavState(), '', url);

if (typeof options.dispatch === 'undefined' || options.dispatch === true) router.dispatch(url, context)
if (typeof dispatch === 'undefined' || dispatch === true) router.dispatch(url, context)

return url
}

const pushHistory = (routeName, options) => {
options = options || {}
options.dispatch = false
return navigate(routeName, options)
}
Expand Down

0 comments on commit 7e5d20b

Please sign in to comment.