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

oiler

v2.2.0

Published

Helper to create basic SPA using React, Baobab and Fetchery

Downloads

26

Readme

Oiler

Helper to create basic SPWA using React, Baobab and Fetchery written in typescript

And baobab-router

Getting started

This section is a quick overview of the steps to setup an application.

State

Application data is stored in a Baobab tree.

import oiler from 'oiler';

// init state
oiler.state.set({ foo: 'bar' });

Services

Services are declared using Fetchery to query APIs.

import oiler, { Fetchery } from 'oiler';

oiler.addClient(
  'api', // service name
  'https://foo.bar', // service base url
  {
    // Fetchery defaults
    contentType: Fetchery.CONTENT_TYPE.JSON,
  },
  {
    // API routes
    'foo.bar': { route: '/foo/bar', method: Fetchery.METHOD.POST },
  }
);

A simple example can be found in ./dev/services/api.ts.

actions

Actions are async functions that handle application logic (call services, update state).

foo.js

export const foo = async (oiler, data) => {
  oiler.state.set(['foo'], data);
};

bar.js

export const bar = async (oiler, data) => {
  oiler.state.set(['bar'], data);
};

actions.js

import oiler from 'oiler';

import { foo } from './foo';
import { bar } from './bar';

oiler.addAction('foo', foo);
oiler.addAction('bar', bar);

A simple example can be found in ./dev/actions.

Pages & modals

import oiler from 'oiler';

const FooBar = function (props) {
  return <div>Foo bar</div>;
};

// Define route and state (pages only)
FooBar.route = '/foo/bar/:id';
FooBar.state = { id: ':id' };
// Actions to execute on page/modal display
FooBar.dependencies = [{ action: ['foo'] }, { action: ['bar'] }];
// Set header/footer display (pages only)
FooBar.header = true;
FooBar.footer = false;

// Register page to app
oiler.addPage('foo.bar', FooBar);

A simple example can be found in ./dev/pages and ./dev/modals.

Layout

Header & footer

It is possible to set some header and footer components to be displayed before and after pages.

import oiler from 'oiler';

oiler.Header = function () {
  return <div>Header</div>;
};
oiler.Footer = function () {
  return <div>Footer</div>;
};

Page & modal wrappers

It is possible to set wrapper around pages and modals components to handle specific layout and logic.

import oiler from 'oiler';

oiler.ModalWrapper = function ({ children }) {
  return <div className="modal">{children}</div>;
};

Navigation

open

Open registered page or modal

import oiler, { CONTAINERS } from 'oiler';

// open a page with uuid
oiler.open({
  id: 'foo.bar',
  container: CONTAINERS.PAGE,
  uuid: 'some-id',
});

// open modal with metadata
oiler.open({
  id: 'foo.bar',
  container: CONTAINERS.MODAL,
  metadata: { foo: 'bar' },
});

refresh

This method reload page or modal (triggers actions dependencies).

import oiler, { CONTAINERS } from 'oiler';

// refresh page
oiler.refresh(CONTAINERS.PAGE);

// refresh modal
oiler.refresh(CONTAINERS.MODAL);

Initialization

Once pages and modals are registered, application needs to be initialized to create the router and render.

import oiler from 'oiler';

// will render application in #container
// and use page ['foo', 'bar'] as default page
oiler.start('container', ['foo', 'bar']);

Advanced

Authentication

login

This method enable access to pages defined with authenticated=true.

logout

This method restrict access to pages defined with authenticated=false.

Locales

Oiler uses node-polyglot to handle I18n.

See dev's "About" page and dev's locales as a simple example.

addLocale

Used to register an available language in the application by providing a name and a URL to a JSON file containing texts.

import oiler from 'oiler';

oiler.addLocale('en', '/locales/en.json');
oiler.addLocale('fr', 'https://foo.bar/locales/fr.json');

To load locale on start, locale name must be passed as the third parameter of oiler.start.

setLocale

Load locale file from URL and re-render.

import oiler from 'oiler';

await oiler.setLocale('fr');

text

Returns text for the provided key, all parameters are passed to polyglot.t for interpolation (see node-polyglot for more details).

import oiler from 'oiler';

// In a page component
const FooBar = function ({ oiler }) {
  // use text from locale
  return <div>{oiler.text('foo.bar')}</div>;
};

Events

start

Emit when oiler.start is called.

open

Emit with page/modal parameters when oiler.open is called.

refresh

Emit with page/modal parameters when oiler.refresh is called.

login

Emit when oiler.login is called.

logout

Emit when oiler.logout is called.

Development

Run npm run dev to start dev server in watch mode on port 8080

Contributions

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to run npm run lint.

License

MIT