forked from FabricLabs/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocument.js
44 lines (35 loc) · 958 Bytes
/
document.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
const Vector = require('./vector');
class Document extends Vector {
constructor (doc) {
super(doc);
// only valid if this matches
this.contract = {
integrity: `sha256-${this.hash}`
};
return this;
}
/**
* Compiles an `input` {@link Vector}.
* ENV provides the name of a parent type (e.g., "scaffold" or "0xDEADBEEF...")
* UI provides the name of the desired component
* @param {Vector} input [env, ui]
* @return {Promise} Promise which resolves on compilation.
*/
async compile (input) {
let vector = new Vector(input)._sign();
let contract = [
`extends ${input[0]}`,
`block body`,
` ${input[1]}(state="${vector.id}") {{state}}`
].join('\n');
this.contract = contract;
this['@id'] = vector.id;
await this.commit();
return contract;
}
toString () {
return `<Document id="${this.id}" />`;
}
}
module.exports = Document;