dapp¶
Source | dapp |
---|
The DApp library is a collection of several functions to handle DApp loading, starting and depdency resolve.
getSplittedVersion¶
dapp.getSplittedVersion(versionString);
Splits an version, removes non number characters, reduce length to 3 and adds missing numbers.
Parameters¶
versionString
-string
(optional): Version that should be splitted (eg. “0.1.0”)
Returns¶
Array<number|string>
: The splitted version.
getVersionDBCPHashFromDAppVersion¶
dapp.getVersionDBCPHashFromDAppVersion(requiredVersion, childENS, childDefinition);
Returns the ipfs hash to the dbcp of the child with the correct version.
Parameters¶
requiredVersion
-string
: version that should be loaded from the childchildENS
-string
: ens address of the child (the current deployed version is not listed in the versions object, the function sets the ens address within the versions object with the current version)childDefinition
-any
: The version dbcp hash from the specific DApp version.
Returns¶
string
: The version dbcp hash from the specific DApp version.
Example¶
getVersionDBCPHashFromDAppVersion(
dependencies[dependency],
dependency,
subDefinition
)
// returns : Qmb...
getDAppDependencies¶
dapp.getDAppDependencies(originName, ensDefinition, depTree, deep);
Loads all (sub) dependencies dbcp’s of the provided dapp and set systemjs maps to the correct dbcp hashes. Explanation:
- load the latest dbcp.json from the dapp ens address
- after this, the correct lib ipfs hash gets extracted from the version history of the latest dbcp.json
- the new definition will loaded from the extracted ipfs hash and this versions will be overwritten by the latest one, to be sure, that all versions, including the latest one, are included
- the used definition will now not the latest one, only the correct dbcp description of the desired version
- dev version only used for DApps, that also requires the latest current version of the library
Parameters¶
originName
-string
: name of the module that should be traversed;ensDefinition
-any
: ens definition of the module that should be traversed (iterate through dependencies);depTree
-Array<Array<n>>
(default = [ ]): dependency tree of a DApp;deep
-number
(default = 0): recursion count to prevent recursive dependency;
Returns¶
Promise
returns Array<Array<n>>
: dependency tree of a DApp
Example¶
await getDAppDependencies(dappEns, ensDefinition);
// returns: [
// [],
// [
// {
// "name": "angular-libs",
// "definition": {
// ...
// },
// "location": "angularlibs.evan!dapp-content"
// }
// ],
// [
// {
// "name": "angular-core",
// "definition": {
// ...
// },
// "location": "angularcore.evan!dapp-content"
// }
// ]
// ]
loadDAppDependencies¶
bcc.loadDAppDependencies(dappEns, useDefaultDomain);
Load all dependencies of the dapp using SystemJS and register its ens names, so each DApp can load the dependency using it within import statements.
import {
...
} from 'angular-core';
Parameters¶
dappEns
-object
: ens of the dappuseDefaultDomain
-boolean
(optional): decide if the default domain should be used
Returns¶
Promise
returns any
: ens definition from the DApp
Example¶
dapp.loadDAppDependencies(dappEns, useDefaultDomain);
// returns ens definition
// {
// "name": "angular-libs",
// "definition": {
// ...
// },
// "location": "angularlibs.evan!dapp-content"
// }
loadDApp¶
dapp.loadDApp(dappEns, useDefaultDomain);
loads a DApp description and register it’s dependencies. Returns the js exported module and the loaded ens definition.
Parameters¶
dappEns
-object
: ens of the dappuseDefaultDomain
-boolean
(optional): decide if the default domain should be used
Returns¶
Promise
returns any
: returns { module: { … }, ensDefinition: {…}}
Example¶
loadDApp('dashboard', true);
// returns:
// {
// module: loadedModule,
// ensDefinition: ensDefinition
// }
startDApp¶
dapp.startDApp(dappEns, container, useDefaultDomain);
Loads an DApp from ENS, resolves it’s dependencies and runs the startDApp function or, in case of an html entrypoint, adds an iframe and loads the url.
Parameters¶
dappEns
-object
: ens address to load the dapp fromcontainer
-Element
(default = document.body): element where DApp was starteduseDefaultDomain
-boolean
(optional): decide if the default domain should be used
Returns¶
Promise
returns void
: resolved when DApp started
getDomainName¶
dapp.getDomainName(...subLabels);
builds a full domain name for the current bcc config
Parameters¶
Array<string>
-subLabels
: used to enhance nameResolver config
Returns¶
The domain name
: The domain name.
Example¶
ensDomain = `bcc.${ getDomainName() }!dapp-content`
// returns: bcc.evan!dapp-content