Commit 9fb034bef38565313b13d8e7de173a14de9812df
added option param to container register
wanderer committed on 5/30/2017, 11:32:12 PMParent: ccb48716869c61d77e5c9797dab1dfde9f8bf4f8
Files changed
exoInterface.js | changed |
index.js | changed |
package.json | changed |
portManager.js | changed |
exoInterface.js | ||
---|---|---|
@@ -31,9 +31,9 @@ | ||
31 | 31 | exoInterface: this |
32 | 32 | }, opts)) |
33 | 33 | |
34 | 34 | this._waitingMap = new Map() |
35 | - this.container = new opts.Container(this) | |
35 | + this.container = new opts.container.Constructor(this, opts.container.args) | |
36 | 36 | |
37 | 37 | // once we get an result we run the next message |
38 | 38 | this.on('result', this._runNextMessage) |
39 | 39 |
index.js | ||
---|---|---|
@@ -70,13 +70,13 @@ | ||
70 | 70 | * @param {Object} the entry port |
71 | 71 | * @param {Object} the parent port |
72 | 72 | */ |
73 | 73 | async createInstance (type, state, entryPort = null, parentPort) { |
74 | - const Container = this._containerTypes[type] | |
74 | + const container = this._containerTypes[type] | |
75 | 75 | |
76 | 76 | if (!state) { |
77 | 77 | state = { |
78 | - '/': Container.createState() | |
78 | + '/': container.Constructor.createState() | |
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | 82 | // create a new kernel instance |
@@ -84,9 +84,9 @@ | ||
84 | 84 | entryPort: entryPort, |
85 | 85 | parentPort: parentPort, |
86 | 86 | hypervisor: this, |
87 | 87 | state: state, |
88 | - Container: Container | |
88 | + container: container | |
89 | 89 | }) |
90 | 90 | |
91 | 91 | // save the newly created instance |
92 | 92 | this._containerInstances.set(entryPort, exoInterface) |
@@ -107,11 +107,15 @@ | ||
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
110 | 110 | * regirsters a container with the hypervisor |
111 | - * @param {String} the name of the type | |
112 | - * @param {Class} a Class for instantiating the container | |
111 | + * @param {String}i type - the name of the type | |
112 | + * @param {Class} Constructor - a Class for instantiating the container | |
113 | + * @param {*} args - any args that the contructor takes | |
113 | 114 | */ |
114 | - registerContainer (type, vm) { | |
115 | - this._containerTypes[type] = vm | |
115 | + registerContainer (type, Constructor, args) { | |
116 | + this._containerTypes[type] = { | |
117 | + Constructor: Constructor, | |
118 | + args: args | |
119 | + } | |
116 | 120 | } |
117 | 121 | } |
package.json | ||
---|---|---|
@@ -41,8 +41,9 @@ | ||
41 | 41 | "documentation": "^4.0.0-rc.1", |
42 | 42 | "ipfs": "^0.23.1", |
43 | 43 | "istanbul": "^1.1.0-alpha.1", |
44 | 44 | "primea-message": "0.0.1", |
45 | + "primea-wasm-container": "0.0.0", | |
45 | 46 | "standard": "10.0.2", |
46 | 47 | "tape": "^4.5.1" |
47 | 48 | } |
48 | 49 | } |
portManager.js | ||
---|---|---|
@@ -158,11 +158,11 @@ | ||
158 | 158 | * @param {*} data - the data to populate the initail state with |
159 | 159 | * @returns {Object} the newly created port |
160 | 160 | */ |
161 | 161 | create (type, data) { |
162 | - const Container = this.hypervisor._containerTypes[type] | |
162 | + const container = this.hypervisor._containerTypes[type] | |
163 | 163 | return this._createPortObject(type, { |
164 | - '/': Container.createState(data) | |
164 | + '/': container.Constructor.createState(data) | |
165 | 165 | }) |
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
Built with git-ssb-web