{"id":19168792,"url":"https://github.com/brigjs/brig-module","last_synced_at":"2025-02-22T23:41:02.455Z","repository":{"id":66276876,"uuid":"95412169","full_name":"BrigJS/brig-module","owner":"BrigJS","description":"Framework to implement module for brig","archived":false,"fork":false,"pushed_at":"2017-07-04T04:26:03.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-14T06:38:16.818Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BrigJS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-26T05:40:11.000Z","updated_at":"2017-07-04T04:25:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"43d3093c-4087-4e05-b723-7bc35d14aa58","html_url":"https://github.com/BrigJS/brig-module","commit_stats":null,"previous_names":["cfsghost/brig-module"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrigJS%2Fbrig-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrigJS%2Fbrig-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrigJS%2Fbrig-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrigJS%2Fbrig-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BrigJS","download_url":"https://codeload.github.com/BrigJS/brig-module/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240250350,"owners_count":19771775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T09:43:48.568Z","updated_at":"2025-02-22T23:41:02.438Z","avatar_url":"https://github.com/BrigJS.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# brig-module\n\nModule framework for brig, to let developer implement own module for brig easily.\n\n[![NPM](https://nodei.co/npm/brig-module.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/brig-module/)\n[![NPM](https://nodei.co/npm-dl/brig-module.png?months=9\u0026height=2)](https://nodei.co/npm/brig-module/)\n\n## Installation\n\nInstall module via NPM\n```shell\nnpm install brig-module\n```\n\n## Create Your NPM module for brig\n\nWith `brig-module`, you can create useful brig module which can be packaged and published to NPM server.\n\n### First Step\n\nThe first step is making preparation for your own NPM package. Create a project which includes structure:\n\n* types/\n  * MyItem.js\n* index.js\n* package.json\n* README.md\n\nNote that: If you don't know how to package a NPM module, please go to NPM official website to learn more.\n\n### Second Step\n\nThe entry of this NPM module is `index.js`, it should contains:\n\n__index.js__\n\n```javascript\nvar BrigModule = require('brig-module');\n\nvar brigModule = new BrigModule();\n\nbrigModule.addType(require('./types/MyItem'));\n\nmodule.export = brigModule;\n```\n\n### Third Step: Create customized type\n\nImplement your QML type by using `BrigModule.TypePrototype`.\n\n__types/MyItem.js__\n\n```javascript\nvar BrigModule = require('brig-module');\n\n// Create prototype of type named MyItem\nvar proto = module.exports = new BrigModule.TypePrototype('MyItem');\n\n// This type has a property named msg, which has default value.\nproto.defineProperty('msg', 'hello');\n\n// This type has a method named sum, which has two parameters\nproto.defineMethod('sum(a,b)', function(a, b) {\n\treturn a + b;\n});\n\n// instance of type was created\nproto.on('instance-created', function(instance) {\n\n\tinstance.on('msgChanged', function() {\n    console.log('msg was changed, new value is ' + insntace.getProperty('msg'));\n\t});\n\n});\n```\n\n### Fourth Step: Package and publish your module\n\nNow you can package your brig module which contains your customized type. Using NPM command to make a link or upload package to NPM server.\n\n```shell\nnpm publish\n```\n\n### Fifth Step: Using your module and customized QML type in your application\n\nLoad your module in your brig application:\n\n__app.js__\n\n```javascript\nconst Brig = require('brig');\nconst brigMyItem = require('brig-myitem');\n\nconst brig = new Brig();\n\nbrig.on('ready', (brig) =\u003e {\n\n  // Load your module\n  brig.loadModule(brigMyItem);\n  \n  brig.open('Application.qml', (err, window) =\u003e {\n    // You have a window here\n  });\n});\n```\n\nThen your customized QML type can be used in QML enviromnet:\n\n__Application.js__\n\n```qml\nimport QtQuick 2.3\nimport QtQuick.Controls 2.0\nimport Brig.MyItem 1.0\n\nApplicationWindow {\n\tvisible: true;\n\tcolor: 'black';\n\ttitle: 'My Application';\n\twidth: 1280;\n\theight: 768;\n\n\tMyItem {\n\t\tid: myItem;\n\t\tmsg: 'new msg';\n\t}\n  \n\tComponent.onCompleted: {\n\t\tvar ret = myItem.sum(1, 2);\n\t\tconsole.log(ret);\n\t}\n}\n```\n\n## License\n\nLicensed under the MIT License\n\n## Authors\n\nCopyright(c) 2017 Fred Chien \u003c\u003ccfsghost@gmail.com\u003e\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrigjs%2Fbrig-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrigjs%2Fbrig-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrigjs%2Fbrig-module/lists"}