The JavaScript Container is an ultra-lightweight library designed to facilitate seamless communication between your other libraries.
import { StratoxContainer } from './node_modules/stratox/src/StratoxContainer.js';
const container = new StratoxContainer();
// Example 1
container.set("someObject", { test: "Container 1" });
console.log(container.get("someObject").test);
// Log response: Container 1
// Example 2
container.set("passingAFunction", function(arg1, arg2) {
alert(arg1+" "+arg2);
});
container.get("passingAFunction", "Hello", "world!");
// Alert response: Hello world!
set(key, value, overwrite);
- key: Unique container key/string identifier
- value: Mixed value of whatever you want to share, e.g. String, number, object, function.
- overwrite: Attempting to set a container multiple times will trigger a warning unless manual consent is provided by setting "overwrite" to true.
setFactory(key, value, overwrite);
- key: Unique factory key/string identifier
- value: callable
- overwrite: Attempting to set a container multiple times will trigger a warning unless manual consent is provided by setting "overwrite" to true.
get(key, ...args);
- key: Unique container key/string identifier
- args: pass arguments to possible factory/function
has(key);
- key: Unique container key/string identifier
isContainer(key);
- key: Unique container key/string identifier
isFactory(key);
- key: Unique factory key/string identifier