brig-module
Module framework for brig, to let developer implement own module for brig easily.
Installation
Install module via NPM
npm install brig-module
Create Your NPM module for brig
With brig-module
, you can create useful brig module which can be packaged and published to NPM server.
First Step
The first step is making preparation for your own NPM package. Create a project which includes structure:
- types/
- MyItem.js
- index.js
- package.json
- README.md
Note that: If you don't know how to package a NPM module, please go to NPM official website to learn more.
Second Step
The entry of this NPM module is index.js
, it should contains:
index.js
var BrigModule = ; var brigModule = ; brigModule; moduleexport = brigModule;
Third Step: Create customized type
Implement your QML type by using BrigModule.TypePrototype
.
types/MyItem.js
var BrigModule = ; // Create prototype of type named MyItemvar proto = moduleexports = 'MyItem'; // This type has a property named msg, which has default value.proto; // This type has a method named sum, which has two parametersproto; // instance of type was createdproto;
Fourth Step: Package and publish your module
Now you can package your brig module which contains your customized type. Using NPM command to make a link or upload package to NPM server.
npm publish
Fifth Step: Using your module and customized QML type in your application
Load your module in your brig application:
app.js
const Brig = ;const brigMyItem = ; const brig = ; brig;
Then your customized QML type can be used in QML enviromnet:
Application.js
import QtQuick 2.3import QtQuick.Controls 2.0import Brig.MyItem 1.0 ApplicationWindow { visible: true; color: 'black'; title: 'My Application'; width: 1280; height: 768; MyItem { id: myItem; msg: 'new msg'; } Component.onCompleted: { var ret = myItem.sum(1, 2); console.log(ret); }}
License
Licensed under the MIT License
Authors
Copyright(c) 2017 Fred Chien <cfsghost@gmail.com>