Skip to content

Commit 756c551

Browse files
authored
Merge pull request #115 from SpringRoll/release/2.3.0
Release/2.3.0
2 parents 3e2a0c3 + 099d56b commit 756c551

File tree

13 files changed

+3842
-4728
lines changed

13 files changed

+3842
-4728
lines changed

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,18 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.3.0] - 2022-03-03
9+
10+
### Added
11+
12+
- Added context object to Container to allow data sharing between Container and plugins
13+
14+
## Changed
15+
16+
- Bumped karma dependency from 5.2.3 to 6.3.14
17+
818
## [2.2.5] - 2022-02-03
9-
- Upgraded follow-redirects dependancy for security alert
19+
- Upgraded follow-redirects dependency for security alert
1020

1121
## Fixed
1222
- Fixed error when reporting a plugin preload failure

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,51 @@ app.on('init', function() {
465465

466466
Any JSON-serializable object can be set as a `playOption`.
467467

468+
## Context
469+
Container has an optional parameter at instantiation time which allows the opener to attach any data they require to the Container
470+
instance which any plugins can interact with to share data. This data can be mutated or replaced at any time.
471+
472+
```javascript
473+
474+
const initialContext = {
475+
hostEnvironment: 'web',
476+
gameBuildInfo: {
477+
commit: '#abcd123',
478+
name: 'game-name'
479+
}
480+
};
481+
482+
const container = new Container('#game', { context: initialContext });
483+
484+
// Once the container instance is created you can access the context from any plugin or anywhere else there is access to Container
485+
console.log(container.context); // { "hostEnvironment": "web", "gameBuildInfo": { "commit": "#abcd123", "name": "game-name" } }
486+
487+
```
488+
489+
The context can be accessed via the `container.context` getter. It can also be modified by simply adding or changing fields
490+
491+
```javascript
492+
container.context.newField = 'hello';
493+
container.context.gamebBuildInfo = 'newInfo';
494+
495+
// { "hostEnvironment": "web", "gameBuildInfo": "newInfo", "newField": "hello" }
496+
console.log(container.context);
497+
```
498+
499+
You can also overwrite the context object entirely if you need to:
500+
501+
```javascript
502+
container.context = {
503+
newField: {
504+
newKey: 'newField'
505+
}
506+
}
507+
```
508+
509+
The only caveat here is that this will check to make sure the new data is an object. If not it will log an error and leave the
510+
context unchanged.
511+
512+
468513
## Saved Data API
469514

470515
The SavedData API is made up of three classes: `SavedData`, `SavedDataHandler`, and the `UserDataPlugin`.

dist/SpringRoll-Container-umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/SpringRoll-Container-umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)