Skip to content

Commit

Permalink
JS - 0.9.68, golos.libs
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Mar 29, 2024
1 parent 37d9a37 commit 080cf88
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
3 changes: 3 additions & 0 deletions golos-lib-js/src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const formatter = require('./formatter')(api);
const memo = require('./auth/memo');
const messages = require('./auth/messages');
const utils = require('./utils');
const Libs = require('./libs')
const { importNativeLibCtx, importNativeLib,
isNativeLibLoaded, assertNativeLib, } = require('./core');

Expand All @@ -29,6 +30,8 @@ const golos = {
utils,
};

new Libs(golos)

if (typeof window !== 'undefined') {
window.golos = golos;
}
Expand Down
9 changes: 7 additions & 2 deletions golos-lib-js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ const memo = require('./auth/memo');
const messages = require('./auth/messages');
const config = require('./config');
const utils = require('./utils');
const Libs = require('./libs')
const ecc = require('./auth/ecc/');
const { importNativeLibCtx, importNativeLib,
isNativeLibLoaded, assertNativeLib, } = require('./core');

module.exports = {
const rootObj = {
importNativeLibCtx,
importNativeLib,
isNativeLibLoaded,
Expand All @@ -29,4 +30,8 @@ module.exports = {
use: middlewares.use,
utils,
ecc,
};
}

new Libs(rootObj)

module.exports = rootObj
37 changes: 37 additions & 0 deletions golos-lib-js/src/libs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

class Libs {
constructor(rootObj) {
this.rootObj = rootObj
rootObj.libs = this
}

add = (lib) => {
const { rootObj } = this
const { libName } = lib
if (!libName) throw new Error('Lib should have field libName')
if (!libName.split) throw new Error('libName should be string')
if (rootObj.libs[libName]) {
rootObj.libs[libName] = lib
return false
} else {
rootObj.libs[libName] = lib
return true
}
}

remove = (libOrName) => {
const { rootObj } = this
const libName = libOrName
if (!libName.split) {
libName = libName.libName
if (!libName) throw new Error('Lib should have field libName')
}
if (rootObj.libs[libName]) {
delete rootObj.libs[libName]
return true
}
return false
}
}

module.exports = Libs

0 comments on commit 080cf88

Please sign in to comment.