Home > Web Front-end > JS Tutorial > Introduction to the use of open source JS plug-in framework MinimaJS

Introduction to the use of open source JS plug-in framework MinimaJS

php中世界最好的语言
Release: 2018-04-16 17:03:28
Original
1603 people have browsed it

This time I will bring you an introduction to the use of the open source JS plug-in framework MinimaJS. What are the precautions when using the open source JS plug-in framework MinimaJS? Here are practical cases, let’s take a look.

MinimaJS, completely open source, source code download address: https://github.com/lorry2018/minimajs. This framework refers to the OSGi specification and implements the three major plug-in functions defined by the specification on Node. MinimaJS has three functions: dynamic plug-in, service and extension. The framework is developed based on VSCode, uses ES6 coding, and is based on Node 8 development, with thousands of lines of code, very simple, elegant and lightweight. The code structure of the framework is clearly divided and elegantly named.

Let’s take a brief look at how to use this framework.

With these lines of code, you can create a plug-in framework and load plug-ins from the current plugins directory.

Each plug-in is in the plugins directory. The basic information, dependency information, services and extensions of the plug-in are defined by plugin.json. This file must be in the plug-in root directory and included. A plug-in consists of plugin.json and other files. Other files are optional and can include js, html, css files, etc. The following is an example of a plug-in. For the plugin.json file, except for the id which is a required attribute, the others are optional, which means that the smallest plug-in is one that only defines plugin.json and the file only declares the plug-in id.

Similar to the OSGi specification, each plug-in can define an activator, which defaults to Activator.js. If the naming is not the default, you need to define the activator file name through activator in plugin.json. A typical Activator is defined as follows, used to declare the entry and exit of the plug-in.

Here start and stop represent entrance and exit respectively, which are used for service registration, binding, event monitoring, etc.

Plug-ins communicate through services, one plug-in registers the service, and the other plug-in consumes the service. Plug-in registration can be declared through plugin.json, or the service can be registered through the addService of the PluginContext parameter of the activator's start method. As shown below, use plugin.json to register a service.

Another plugin that can consume services through an activator.

The framework also provides features such as plug-in extensions and class loading, which can be explored through the examples provided by the framework. The following is a plug-in REST framework. An example built based on plug-in can be obtained by downloading the source code.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

AngularJS makes input box word limit reminder

vue determines whether the user is logged in

The above is the detailed content of Introduction to the use of open source JS plug-in framework MinimaJS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template