npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mini-apps/navigation

v2.0.6

Published

Navigation library for VK Mini Apps

Downloads

5

Readme

Mini Apps Navigation NPM

A package to organize navigation in Mini Apps applications

Installation

yarn add @mini-apps/navigation

or

npm i @mini-apps/navigation

Description

This package was created with aim on mobile applications. So, the main terms which are used in this library are view, modal, popup etc. You should not wait for any Web based terms used in context of Navigator. Here, I tried to recreate a logic used in native mobile applications and waiting for other developers contribution.

Glossary

State

State is like the one of the most often met terms in this project. It is described with view, modal, popup, params and modifiers. Properties modal and popup are not required, but view is. Normally, there cannot be any situation when view is unknown, we should always show something, so that is the reason why view is required. params is passed custom dictionary.

Modifier

Modifier is a modification applied to state. It can be any string and can be used for any purposes.

Classes

BrowserNavigator

BrowserNavigator is adopted for browser and works with window.history. It extends some Navigator methods like on, off and go with some extra lines of code, which are written mostly to interact with browser's history.

It rewires such functions as window.history.pushState and window.history.replaceState, so then, each history item has stable state, which contains current location index and location history.

Usage

Creating instance
import {BrowserNavigator} from '@mini-apps/navigation';

const navigator = new BrowserNavigator();
Initialization

When window.history becomes available, it is required to call navigator init, to make him override window.history.pushState and window.history.replaceState and add event listener to window's popstate event.

navigator.init();

To cancel overrides and remove event listener:

navigator.unmount();
Initial navigator state

To make navigator initialization easier, there is a function extractBrowserNavigatorSettings which returns initial settings for navigator if it is possible.

import {extractBrowserNavigatorSettings} from '@mini-apps/navigation';

// Extract settings from browsers history
const navigatorSettings = extractBrowserNavigatorSettings();

// Initialize with received settings
navigator.init(navigatorSettings ? navigatorSettings : undefined);

If first parameter in init was not passed, navigator watches if current history length is equal to 1, it understands that previously, it was not mounted here before. It replaces current location with modifier root which indicates about root location.

Popstate listener

When mount() is called, navigator adds its own listener, which watches for location changes and automatically updates internal location. The logic is rather simple - it tries to extract location info from history item state and correctly updates navigator. But in case of fail, it will recognize pushed location as new one. So, it will try to parse it and push to navigator. Otherwise, an error will be thrown.