Socket
Socket
Sign inDemoInstall

@soundworks/core

Package Overview
Dependencies
21
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.0-alpha.6 to 4.0.0-alpha.7

2

package.json
{
"name": "@soundworks/core",
"version": "4.0.0-alpha.6",
"version": "4.0.0-alpha.7",
"description": "Open-source creative coding framework for distributed applications based on Web technologies",

@@ -5,0 +5,0 @@ "authors": [

@@ -86,3 +86,3 @@ import BasePluginManager from '../common/BasePluginManager.js';

if (!(client instanceof Client)) {
throw new Error(`[soundworks.PluginManager] Invalid argument, "new PluginManager(client)" should receive an instance of "soundworks.Client as argument"`);
throw new Error(`[soundworks.PluginManager] Invalid argument, "new PluginManager(client)" should receive an instance of "soundworks.Client" as argument`);
}

@@ -89,0 +89,0 @@

@@ -8,24 +8,8 @@ import merge from 'lodash.merge';

constructor(id) {
/**
* User defined ID of the plugin.
*
* @type {string}
* @see {@link client.PluginManager#register}
* @see {@link server.PluginManager#register}
*/
this.id = id;
/** @private */
this._id = id;
/** @private */
this._type = this.constructor.name;
/**
* Type of the plugin, i.e. the ClassName.
*
* Usefull to do perform some logic based on certain types of plugins without
* knowing under which `id` they have been registered. (e.g. creating some generic
* views, etc.)
*
* @type {string}
* @readonly
*/
this.type = this.constructor.name;
/**
* Options of the plugin.

@@ -63,2 +47,28 @@ *

/**
* User defined ID of the plugin.
*
* @type {string}
* @readonly
* @see {@link client.PluginManager#register}
* @see {@link server.PluginManager#register}
*/
get id() {
return this._id;
}
/**
* Type of the plugin, i.e. the ClassName.
*
* Usefull to do perform some logic based on certain types of plugins without
* knowing under which `id` they have been registered. (e.g. creating some generic
* views, etc.)
*
* @type {string}
* @readonly
*/
get type() {
return this._type;
}
/**
* Start the plugin. This method is automatically called during the client or

@@ -65,0 +75,0 @@ * server `init()` lifecyle step. After `start()` is fulfilled the plugin should

@@ -16,3 +16,3 @@ import { isPlainObject, isString } from '@ircam/sc-utils';

/** @private */
this._registeredPlugins = new Map();
this._dependencies = new Map();
/** @private */

@@ -71,10 +71,28 @@ this._instances = new Map();

if (this._registeredPlugins.has(id)) {
throw new Error(`[soundworks:PluginManager] Plugin "${id}" of type "${ctor.name}" already registered`);
if (this._instances.has(id)) {
throw new Error(`[soundworks:PluginManager] Plugin "${id}" already registered`);
}
this._registeredPlugins.set(id, { ctor, options, deps });
// we instanciate the plugin here, so that a plugin can register another one
// in its own constructor.
//
// the dependencies must be created first, so that the instance can call
// addDependency in its constructor
this._dependencies.set(id, deps);
const instance = new ctor(this._node, id, options);
this._instances.set(id, instance);
}
/**
* Manually add a dependency to a given plugin. Usefull to require a plugin
* within a plugin
*
*/
addDependency(pluginId, dependencyId) {
const deps = this._dependencies.get(pluginId);
deps.push(dependencyId);
}
/**
* Returns the list of the registered plugins ids

@@ -84,3 +102,3 @@ * @returns {string[]}

getRegisteredPlugins() {
return Array.from(this._registeredPlugins.keys());
return Array.from(this._instances.keys());
}

@@ -102,5 +120,3 @@

// instanciate all plugins
for (let [id, { ctor, options }] of this._registeredPlugins.entries()) {
const instance = new ctor(this._node, id, options);
this._instances.set(id, instance);
for (let [id, instance] of this._instances.entries()) {
instance.onStateChange(_values => this._propagateStateChange(instance));

@@ -112,3 +128,3 @@ }

const promises = Array.from(this._registeredPlugins.keys()).map(id => this.unsafeGet(id));
const promises = Array.from(this._instances.keys()).map(id => this.unsafeGet(id));

@@ -133,4 +149,4 @@ try {

* Retrieve an fully started instance of a registered plugin, without checking
* that the pluginManager is started. This is important for starting the plugin
* manager itself.
* that the pluginManager has started. This is required for starting the plugin
* manager itself and to require a plugin from within another plugin
*

@@ -144,3 +160,3 @@ * @private

if (!this._registeredPlugins.has(id)) {
if (!this._instances.has(id)) {
throw new Error(`[soundworks:PluginManager] Cannot get plugin "${id}", plugin is not registered`);

@@ -154,3 +170,3 @@ }

// if (!this._instances.has(id)) {
// const { ctor, options } = this._registeredPlugins.get(id);
// const { ctor, options } = this._dependencies.get(id);
// const instance = new ctor(this._node, id, options);

@@ -163,3 +179,3 @@ // this._instances.set(id, instance);

// recursively get the dependency chain
const { deps } = this._registeredPlugins.get(id);
const deps = this._dependencies.get(id);
const promises = deps.map(id => this.unsafeGet(id));

@@ -166,0 +182,0 @@

@@ -81,3 +81,3 @@ import BasePluginManager from '../common/BasePluginManager.js';

if (!(server instanceof Server)) {
throw new Error(`[soundworks.PluginManager] Invalid argument, "new PluginManager(server)" should receive an instance of "soundworks.Server as argument"`);
throw new Error(`[soundworks.PluginManager] Invalid argument, "new PluginManager(server)" should receive an instance of "soundworks.Server" as argument`);
}

@@ -84,0 +84,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc