Skip to content

Commit

Permalink
Fix Event bus error
Browse files Browse the repository at this point in the history
  • Loading branch information
cavearr committed May 26, 2023
1 parent fa3fe06 commit 9ecc9c0
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,39 @@ class BindingWafleEventBus {
constructor() {
this.ver = '2.0';
this.bus = new WafleEventBus();
let _this=this;
let _this = this;
self.addEventListener('message', function (e) {
if(typeof e.data.endpoint !== 'undefined'){
let data=false;
switch(e.data.endpoint){
case 'bus.publish':
data=JSON.parse(e.data.data);
_this.bus.publish(e.data.eventId,data);
break;
case 'worker.API':
if (typeof e.data.endpoint !== 'undefined') {
let data = false;
switch (e.data.endpoint) {
case 'bus.publish':
data = JSON.parse(e.data.data);
_this.bus.publish(e.data.eventId, data);
break;
case 'worker.API':

data=JSON.parse(e.data.data);
switch(e.data.eventId){
case 'getUUID': onPluginGetUUID(data); break;
}
break;
data = JSON.parse(e.data.data);
switch (e.data.eventId) {
case 'getUUID': onPluginGetUUID(data); break;
}
break;
}
}
}
}, false);
if(typeof onPluginGetUUID !== 'undefined'){
self.postMessage({endpoint:'worker.API',eventId:'getUUID'});
if (typeof onPluginGetUUID !== 'undefined') {
self.postMessage({ endpoint: 'worker.API', eventId: 'getUUID' });
}
}

subscribe(eventId, handler, owner,uuid) {
this.bus.subscribe(eventId,handler,owner,uuid);
self.postMessage({endpoint:'bus.subscribe',eventId:eventId, uuid:uuid});
}
subscribe(eventId, handler, owner, uuid) {
this.bus.subscribe(eventId, handler, owner, uuid);
self.postMessage({ endpoint: 'bus.subscribe', eventId: eventId, uuid: uuid });
}

publish(eventId, eventArgs, ownerId) {
// this.bus.publish(eventId,eventArgs,ownerId);
self.postMessage({endpoint:'bus.publish',eventId:eventId, eventArgs:eventArgs, ownerId:ownerId});

// this.bus.publish(eventId,eventArgs,ownerId);
self.postMessage({ endpoint: 'bus.publish', eventId: eventId, eventArgs: eventArgs, ownerId: ownerId });
}

version() {
Expand Down
31 changes: 14 additions & 17 deletions app/resources/libs/Icestudio/Services/WafleEventBus.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ class WafleEventBus {
this.ver = '2.0';
}

eventExists(eventId,event){
if(typeof this.events[eventId] !== 'undefined'){
for(let e in this.events[eventId]){
if(event.owner === this.events[eventId].owner &&
event.handler === this.events[eventId].handler &&
event.uuid === this.events[eventId].uuid )
{
eventExists(eventId, event) {
if (typeof this.events[eventId] !== 'undefined') {
for (let e in this.events[eventId]) {
if (event.owner === this.events[eventId].owner &&
event.handler === this.events[eventId].handler &&
event.uuid === this.events[eventId].uuid) {
return true;
}
}
}
}
return false;
}

removeById(uuid){
removeById(uuid) {

for(let ev in this.events){
for(let i=0;i< this.events[ev].length;i++){
if(this.events[ev][i].uuid=== uuid){
this.events[ev].splice(i, 1);
for (let ev in this.events) {
for (let i = 0; i < this.events[ev].length; i++) {
if (this.events[ev][i].uuid === uuid) {
this.events[ev].splice(i, 1);
}
}
}
Expand All @@ -43,12 +42,12 @@ class WafleEventBus {
if (typeof owner === 'undefined') {
owner = false;
}
let candidate ={
let candidate = {
'owner': owner,
'handler': handler,
'uuid': uuid
};
if(!this.eventExists(candidate)){
if (!this.eventExists(candidate)) {
this.events[eventId].push(candidate);
}
}
Expand All @@ -58,7 +57,6 @@ class WafleEventBus {
if (typeof ownerId === 'undefined') ownerId = 'all';

if (typeof this.events[eventId] !== 'undefined') {

for (let i = (this.events[eventId].length - 1), n = -1; i > n; i--) {
fire = false;
//-- If event has not owner, only call it if no owner of the event is defined or if
Expand All @@ -68,7 +66,6 @@ class WafleEventBus {
} else if (typeof this.events[eventId][i].uuid !== 'undefined' && this.events[eventId][i].uuid === ownerId) {
fire = true;
}

if (fire) {
if (this.events[eventId][i].owner === false) {
this.events[eventId][i].handler(eventArgs);
Expand Down
11 changes: 5 additions & 6 deletions app/resources/libs/Icestudio/Services/WaflePluginManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class WaflePluginManager {
const fs = require('fs');
let _this = this;
fs.readdir(this.pluginDir, function (err, files) {
console.log('PLUGINS::',files);
_this.toload = files.length;
files.forEach(function (file) {
fs.readFile(_this.pluginDir + '/' + file + '/manifest.json', 'utf8', function (err, contents) {
Expand Down Expand Up @@ -114,11 +113,11 @@ class WaflePluginManager {
} else {
_this.plugins[file] = new WaflePluginExtEmbeddedWindowed(args);
}
} else if(typeof args.manifest.gui !== 'undefined' &&
typeof args.manifest.gui.type !== 'undefined' &&
args.manifest.gui.type === 'service'){
_this.plugins[file] = new WaflePluginExtService(args);
}else {
} else if (typeof args.manifest.gui !== 'undefined' &&
typeof args.manifest.gui.type !== 'undefined' &&
args.manifest.gui.type === 'service') {
_this.plugins[file] = new WaflePluginExtService(args);
} else {
_this.plugins[file] = new WaflePlugin(args);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ let collectionsTree = false;
registerEvents();

//Getting environment config, event that start everything inside the plugin
iceStudio.bus.events.publish('pluginManager.getEnvironment',false,pluginUUID);
iceStudio.bus.events.publish('pluginManager.getEnvironment');

76 changes: 36 additions & 40 deletions app/resources/plugins/collectionManager2/js/events.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,60 @@
//-- When some change in the configuration or in the environment, launch it
function setupEnvironment(env){
function setupEnvironment(env) {


iceStudio.bus.events.publish('collectionService.isIndexing');
console.log('Configuración Collectionmanager',env);
}

let preload=false; //-- Flag for preload collection tree from database while indexing the new one.
let preload = false; //-- Flag for preload collection tree from database while indexing the new one.

//-- When index event in the collection service fired
function collectionsIndexStatus(status)
{
function collectionsIndexStatus(status) {

if(status.queue===0 && status.indexing===false){
if (status.queue === 0 && status.indexing === false) {
iceStudio.bus.events.publish('collectionService.getCollections');
}else{
if(preload===false){
preload=true;
} else {
if (preload === false) {
preload = true;
iceStudio.bus.events.publish('collectionService.getCollections');
}
setTimeout(function(){
iceStudio.bus.events.publish('collectionService.isIndexing');
},1000);
setTimeout(function () {
iceStudio.bus.events.publish('collectionService.isIndexing');
}, 1000);
}
}

function collectionsRender(tree)
{
if(tree !== false){
let playground = iceStudio.gui.el('.playground',pluginHost);
collectionsTree = new WafleUITree();
collectionsTree.setId(pluginUUID);
collectionsTree.setTree(tree);

if(playground.length){
playground[0].innerHTML=collectionsTree.render();
collectionsTree.setDomRoot(pluginHost);
iceStudio.gui.activateEventsFromId(`#tree-view-${pluginUUID}`,pluginHost,mouseEvents);
}
function collectionsRender(tree) {
if (tree !== false) {
let playground = iceStudio.gui.el('.playground', pluginHost);
collectionsTree = new WafleUITree();
collectionsTree.setId(pluginUUID);
collectionsTree.setTree(tree);

if (playground.length) {
playground[0].innerHTML = collectionsTree.render();
collectionsTree.setDomRoot(pluginHost);
iceStudio.gui.activateEventsFromId(`#tree-view-${pluginUUID}`, pluginHost, mouseEvents);
}
}
}

function registerEvents()
{
iceStudio.bus.events.subscribe('pluginManager.getEnvironment', setupEnvironment,false, pluginUUID);
iceStudio.bus.events.subscribe('pluginManager.updateEnv', setupEnvironment,false,pluginUUID);
iceStudio.bus.events.subscribe('collectionService.indexStatus',collectionsIndexStatus,false,pluginUUID);
iceStudio.bus.events.subscribe('collectionService.collections',collectionsRender,false,pluginUUID);
function registerEvents() {
iceStudio.bus.events.subscribe('pluginManager.env', setupEnvironment, false, pluginUUID);
iceStudio.bus.events.subscribe('pluginManager.updateEnv', setupEnvironment, false, pluginUUID);
iceStudio.bus.events.subscribe('collectionService.indexStatus', collectionsIndexStatus, false, pluginUUID);
iceStudio.bus.events.subscribe('collectionService.collections', collectionsRender, false, pluginUUID);
}

function mouseEvents(eventType,handler,args)
{
switch(eventType)
{
function mouseEvents(eventType, handler, args) {
switch (eventType) {
case 'click':
switch(handler){
switch (handler) {
case 'this.toggleFolder':
collectionsTree.toggle(pluginHost,args.id);
break;
collectionsTree.toggle(pluginHost, args.id);
break;
case 'this.getBlock':
collectionsTree.getBlock(pluginHost,args);
break;
collectionsTree.getBlock(pluginHost, args);
break;
}
break;
}
Expand Down

0 comments on commit 9ecc9c0

Please sign in to comment.