Skip to content

Commit 03706c2

Browse files
committed
added ephemeral, removed some logs
1 parent 559e78e commit 03706c2

File tree

6 files changed

+25
-19
lines changed

6 files changed

+25
-19
lines changed

actions/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ module.exports = {
22

33

44
enablePlugin : (plugin) => ({type : "PLUGIN_ENABLED", plugin}),
5-
provideService : (serviceType, service, provider) => ({type : "SERVICE_PROVIDED", serviceType, service, provider}),
5+
provideService : (serviceType, service, provider, ephemeral) => ({type : "SERVICE_PROVIDED", serviceType, service, provider, ephemeral}),
66

77
}

config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module.exports = {
1111
if(typeof config === "function"){
1212
config = await config();
1313
}
14-
console.log(config, "CONFIG!");
1514
let pluginConfigs = config.plugins;
1615
let clientConfigs = pluginConfigs.reduce((acc, plugin) => {
1716
let pluginPackage = this.getPluginPackage(configPath, plugin)

effects/consume.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const GeneratorFunction = (function*(){}).constructor;
33

44

55
function* serviceConsumer(channel){
6-
console.log(channel);
76
if(channel instanceof GeneratorFunction){
87
channel = yield call(channel);
98
}

pluginbot.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class Pluginbot extends PluginbotBase {
3737
return resolve("plugin " + pluginName + " already enabled");
3838
}
3939
// let imports = this.buildImports(pluginPkgPart);
40-
console.log("INSTALLING PLUGIN: ", pluginName);
4140

4241
//todo : switch this to thunk instead of callback?
4342
this.runSaga(this._install.bind(this), plugin, pluginName, callback);

src/plugin.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,18 @@ class Plugin {
3333

3434
}
3535

36-
static *provideServices(services, provider){
36+
static *provideServices(services, provider, ephemeral=false){
3737
for(let [key, value] of Object.entries(services)){
3838
if(Array.isArray(value)){
39-
yield all(value.map(service => put(provideService(key, service, provider))))
39+
yield all(value.map(service => put(provideService(key, service, provider, ephemeral))))
4040
}else {
4141
yield put(provideService(key, value, provider));
4242
}
4343
}
4444
}
4545

46-
provide(services){
47-
console.log("Providing serv!");
48-
return call(Plugin.provideServices, services, this)
46+
provide(services, options={}){
47+
return call(Plugin.provideServices, services, this, options.ephemeral)
4948
}
5049

5150
//todo: do we need installation configurations?
@@ -63,7 +62,6 @@ class Plugin {
6362
} else {
6463
yield put({type: "PLUGIN_INSTALLED", pluginName: pluginName});
6564
}
66-
console.log("PLUGIN INSTALLED!", pluginName);
6765
done();
6866

6967
}catch(error){
@@ -74,7 +72,6 @@ class Plugin {
7472

7573
*enable(channels){
7674
yield put(enablePlugin(this));
77-
console.log("STARTED PLUGIN " + this.name, this.plugin);
7875
if(this.plugin.run) {
7976
let run = yield fork(this.plugin.run, this.config, this.provide, channels);
8077
}

src/pluginbot-base.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ class PluginbotBase {
7878
return state;
7979
case "SERVICE_PROVIDED" :
8080
let services = state.services[action.serviceType];
81+
//ephemeral services don't stay in store.
82+
if(action.ephemeral){
83+
return state;
84+
}
8185
if (services) {
8286
services.push(action.service);
8387
} else {
@@ -119,9 +123,7 @@ class PluginbotBase {
119123
}
120124

121125
let pluginSaga = function*(consumptionChannels){
122-
console.log("PLUGIN SAGA!");
123126
let enablePlugin = yield call(plugin.enable.bind(plugin), consumptionChannels);
124-
console.log("plugin done?");
125127
return enablePlugin;
126128

127129
};
@@ -140,11 +142,9 @@ class PluginbotBase {
140142

141143
//start enabling all plugins
142144
for(let [pluginName, pluginSaga] of Object.entries(rootSaga)){
143-
console.log(pluginName, pluginSaga)
144145
pluginTasks[pluginName] = yield fork(pluginSaga, allChannels[pluginName]);
145146
}
146147

147-
console.log("plugins running")
148148
resolve(self.plugins);
149149

150150
}));
@@ -167,6 +167,18 @@ class PluginbotBase {
167167
action.done(pluginEnabled);
168168
})
169169
}))
170+
171+
// this.tasks.push(sagaMiddleware.run(function*(){
172+
// yield takeEvery("INSTALL_PLUGIN", function*(action){
173+
// let plugin = action.plugin;
174+
// if(self.plugins[plugin.pluginName]){
175+
// console.error("Plugin " + plugin.name + " is already installed + enabled");
176+
//
177+
// }else{
178+
// yield call(self._install.bind(self), plugin.plugin, plugin.pluginName)
179+
// }
180+
// })
181+
// }))
170182
})
171183
}
172184

@@ -190,9 +202,11 @@ class PluginbotBase {
190202
return (new Proxy({}, channelHandler));
191203
}
192204

193-
*_install(pluginFunctions, pluginName, done){
205+
//todo: take in plugin object instead of parts .
206+
//todo: stop using done?
207+
*_install(pluginFunctions, pluginName, done=()=>{}){
194208
if(this.plugins[pluginName]){
195-
console.error("plugin already enabled");
209+
console.error("plugin already installed and enabled");
196210
done();
197211
}
198212
try {
@@ -201,12 +215,10 @@ class PluginbotBase {
201215

202216

203217
yield call(this.config.install.bind(this), this._getLazyChannels() , pluginName, pluginFunctions.install);
204-
console.log("configured install donner!");
205218
} else if(pluginFunctions.install) {
206219
yield call(pluginFunctions.install);
207220
}
208221
yield put({type: "PLUGIN_INSTALLED", pluginName: pluginName});
209-
console.log("PLUGIN INSTALLED!", pluginName);
210222
done();
211223
}catch(error){
212224
done(error);

0 commit comments

Comments
 (0)