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
Closed

Add a broadcast event for applications via core #64

andersevenrud opened this issue Feb 23, 2019 · 4 comments

Comments

@andersevenrud
Copy link
Member

@andersevenrud andersevenrud 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
Copy link
Member Author

@andersevenrud andersevenrud 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
Adds support for broadcasting a 'broadcast' event across all filtered
applications.
@andersevenrud
Copy link
Member Author

@andersevenrud andersevenrud commented Feb 23, 2019

Published with osjs/client@3.0.49.

@andersevenrud
Copy link
Member Author

@andersevenrud andersevenrud commented Feb 23, 2019

This was changed to:

broadcast(pkg, name, ...args)

@andersevenrud
Copy link
Member Author

@andersevenrud andersevenrud commented Feb 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant