Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a broadcast event for applications via core #64

Closed
andersevenrud opened this issue Feb 23, 2019 · 4 comments

Comments

Projects
None yet
1 participant
@andersevenrud
Copy link
Member

commented Feb 23, 2019

It would be nice if it was possible to broadcast a messages to application(s) by name without setting up a custom event bus.

// Implementation
class Core {
  broadcast(packageName, ...args) {
    const apps = findAppsByName(packageName);
    apps.forEach(a => a.emit('broadcast', ...args);
  }
}

// Application subscription
proc.on('broadcast', (...args) => console.log(args)); // [1, 2, 3]

// Usage
core.broadcast('FileManager', 1, 2, 3);

This sort of mimics the osjs/server functionality but not based on a connection: https://github.com/os-js/osjs-server/blob/master/src/core.js#L234

Ref: https://community.os-js.org/t/how-do-you-store-data-in-os-js/343

@andersevenrud

This comment has been minimized.

Copy link
Member Author

commented Feb 23, 2019

The broadcast method could also accept a function instead of a string as the first argument:

broadcast(pkg, ...args) {
  const filter = typeof pkg === 'function'
    ? pkg
    : p => p.metadata.name === pkg;

  const apps = findAppsByFilter(filter);
  // ...
}

@andersevenrud andersevenrud self-assigned this Feb 23, 2019

andersevenrud added a commit that referenced this issue Feb 23, 2019

Added Core#broadcast (#64)
Adds support for broadcasting a 'broadcast' event across all filtered
applications.
@andersevenrud

This comment has been minimized.

Copy link
Member Author

commented Feb 23, 2019

Published with osjs/client@3.0.49.

@andersevenrud

This comment has been minimized.

Copy link
Member Author

commented Feb 23, 2019

This was changed to:

broadcast(pkg, name, ...args)

@andersevenrud

This comment has been minimized.

Copy link
Member Author

commented Feb 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.