mobrix-engine-plugin-url-checker
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

MoBrix-engine-plugin-url-checker

NPM npm npm bundle size Maintenance



Handle URL parameters with MoBrix-engine system



Summary



Getting started


Installation

Check MoBrix-engine guide to init the system

If you want to use this plugin with MoBrix-engine, install it:

npm i mobrix-engine-plugin-url-checker

Usage

Include this plugin inside your mobrix-engine config file, and optionally set the urlChecker field, with the plugin settings. For example, to add a custom query parameter:

// Inside your MoBrix-engine config file

const urlCheckerPlugin = require("mobrix-engine-plugin-url-checker");

const config = {
  appName: "custom-app",
  plugins: [urlCheckerPlugin],
  urlChecker: {
    queryParameters: {
      testParam: ({ config, store, urlParam }) => {
        alert("test value" + urlParam);
      },
    },
    preInit: ["testParam"],
  },
};

module.exports = { config };

You can see a live preview by visiting MoBrix-engine-playground

API

Config

This plugin adds a custom field inside the MoBrix-engine config, urlChecker. This new field contains 3 fields, to easily integrate new functions. You can also set this new field with your custom handlers, for any parameter:

  • queryParameters : a dictionary with all custom query parameter handlers (the key is the custom parameter name, and the value is the callback associated). A parameter handler is a callback function that takes an input object, containing the config, the store (null if not already created) and the value of the query parameter (when it is included inside url), called urlParam
  • before : parameters handlers called before the store init process
  • after : parameters handlers called after the store init process

Internally, this plugin has 2 query parameter handler pre-set:


Integration with other plugins

This plugin expose some fields to work with any other plugin. If you want to interact with it, using your custom plugin, add an interaction with urlChecker inside your custom plugin:

//Just a skeleton of a custom plugin that interacts with url-checker plugin
const customPlugin = () => ({
  // Custom plugin stuffs

  interactions: [
    {
      plugin: "mobrix-engine-url-checker",
      effect: (field) => {
        //Add the custom handler
        field.queryParameters["testParam"] = ({ config, urlParam, store }) =>
          alert("param value : " + urlParam);

        //In this example, we want to process the param after the store creation, so we add it to postInit array
        field.postInit.push("testParam");
      },
    },
  ],
});


Included libraries



Authors



License

This project is licensed under the MIT License - see the LICENSE file for details

Readme

Keywords

none

Package Sidebar

Install

npm i mobrix-engine-plugin-url-checker

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

17.8 kB

Total Files

11

Last publish

Collaborators

  • cianciarusocataldo