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

@brandup/ui-app

v1.0.22

Published

Basic infrastructure framework for web applications.

Downloads

125

Readme

@brandup/ui-app

Lightweight, fast and extensible application framework. Full async support. Weight after minification is less than 10KB!

Build Status

Installation

Install NPM package @brandup/ui-app.

npm i @brandup/ui-app

This package support TypeScript language.

Configure and run application

Configure your application with middlewares and run.

import { ApplicationBuilder } from "@brandup/ui-app";
import pages from "./middlewares/pages";
import "./styles.less";

// Customize application model
interface ExampleApplicationModel extends ApplicationModel {
}

// Customize application type
export class ExampleApplication extends Application<ExampleApplicationModel> {
}

const builder = new ApplicationBuilder<ExampleApplicationModel>();
builder
	.useApp(ExampleApplication)
	.useMiddleware(pages);

const appModel: ExampleApplicationModel = {};
const app = builder.build<ExampleApplicationModel>({ basePath: "/" }, appModel);

app.run({ /*optional context params*/ })
	.then(context: StartContext => { })
	.catch(reason => { });

Default HTMLElement of application is document.body. Set custom element:

const appElement = document.getElementById("app")
app.run({ /*optional context params*/ }, appElement);

Navigation

Example links for application navigation app.nav({ url: "url" }):

<a href="url" class="applink">text</a>
<button data-nav-url="url">text</button>

Replace current url app.nav({ url: "url", replace: true }):

<a href="url" class="applink" data-nav-replace>text</a>
<button data-nav-url="url" data-nav-replace>text</button>

The element's click event will start a chain of navigate method calls for all middleware.

During navigation and until it is completed, the loading class is added to the element that started the navigation.

Submit form

<form class="appform">
	<input type="text" name="value" />
</form>

The form's submit event will start a chain of submit method calls for all middleware. Class appform is required.

If the form method is GET, then navigation with the form data will start.

Middlewares

Inject to application lifecycle event methods. Middleware methods are called one after another in the order in which they were registered in the ApplicationBuilder.

class PagesMiddlewareImpl implements Middleware {
	name = "pages"; // unique name of this middleware

    start(context: StartContext<ExampleApplication>, next: MiddlewareNext) {
        console.log("start");

		// context.app - access to application members
		// context.data - get or set context data

		return next();
    }

    async loaded(context: StartContext<ExampleApplication>, next: MiddlewareNext) {
        console.log("loaded");

		return next();
    }

    async navigate(context: NavigateContext<ExampleApplication, PageNavigationData>, next: MiddlewareNext) {
        if (context.replace)
            location.replace(context.url);
        else
            location.assign(context.url);

		return next();
    }

    async submit(context: SubmitContext<ExampleApplication>, next: MiddlewareNext) {
        console.log("submit");

		return next();
    }

    async stop(context: StopContext<ExampleApplication>, next: MiddlewareNext) {
        console.log("stop");

		return next();
    }
}

/** External interface of middleware. */
export interface PagesMiddleware {
}

export default () => new PagesMiddlewareImpl();

Example SPA navigation middleware: example/src/frontend/middlewares/pages.ts

Access to middleware

Retrivie middleware by unique name:

const pages = app.middleware<PagesMiddleware>("pages");

Async execution

export class PagesMiddleware implements Middleware {
	async navigate(context: NavigateContext, next: MiddlewareNext) {
        // Exec before next middleware

		await next();

        // Exec after next middleware
    }
}

Redirect navigation

export class AuthMiddleware implements Middleware {
	async navigate(context: NavigateContext, next: MiddlewareNext) {
        await context.redirect({ url: "url" });
    }

	async submit(context: SubmitContext, next: MiddlewareNext) {
        await context.redirect({ url: "url" });
    }
}

The redirect method will always throw an exception with reason NAV_OVERIDE_ERROR constant and end the current navigation.