Skip to content
This repository was archived by the owner on May 8, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.1.0] - Unreleased
## [4.0.0] - Unreleased

### Changed

Expand Down Expand Up @@ -41,6 +41,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `webpack` ^5.8.22 --> ^5.97.1
- `whatwg-fetch` ^3.0.0 --> ^3.6.20

### Removed

- Removed UserData plugin and SavedData Handler. The UserData plugin has been moved to platform code and can be managed for the website in the `pbs/pbs-kids-website` project. [Part of ticket](https://pbskids.atlassian.net/browse/WEB-105)

## [3.0.0] - 2025-01-03

This is the start of the websquad's fork of https://github.com/pbs/SpringRollContainer to be used in the pbskids redesign (project name "Puma").
Expand Down
149 changes: 0 additions & 149 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,155 +527,6 @@ The only caveat here is that this will check to make sure the new data is an obj
context unchanged.


## Saved Data API

The SavedData API is made up of three classes: `SavedData`, `SavedDataHandler`, and the `UserDataPlugin`.
It allows the container (or the SpringRoll Application) to store key-value pairs in local/session storage. It also gives access to the
IndexedDB API.
It is primarily used to store user data for use across the SpringRoll environment. Examples are listed below for each class.

### SavedData

The `SavedData` class is the most direct way to access the Container storage options. It is used primarily in plugin classes, but may be used wherever necessary.

The following is an example of interacting with Local/Session Storage

```javascript
import { SavedData } from 'springroll-container';

//the last argument, tempOnly, is optional (default = false) and decides whether the value should be saved in session (temporary),
//or local (not temporary) storage.
const tempOnly = false;
SavedData.write('user-value-key', 'user-value', tempOnly);

//SavedData.read() checks localStorage first and then sessionStorage. If the key exists in both only the localStorage will be returned.
let data = SavedData.read('user-value-key'); //data will be either the value in storage, if it exists, or null if it does not.

SavedData.remove('user-value-key'); //removes the value from both local and session storage.
```

The following is an example of interacting with [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) through the UserData class

``` javascript
import { SavedData } from 'springroll-container';

// Firstly, construct the SavedData object. This is only needed for IndexedDB work
const savedData = new SavedData('dbName');

// Then, open a connection to the database (this is using all default parameters, more info on parameters below)
savedData.IDBOpen('dbName','1', {}, {}, (result) => console.log(result))

```

If you want to make changes to the strucutre of the DB you would do so during the open connection step
via Additions and Deletions:

Additions is an optional parameter expecting a JSON object with any additions to the databases structure namely new [stores](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/createObjectStore) and [indexes](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/createIndex). These are placed inside of an array

Deletions is an optional parameter used to delete any [indexes](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/deleteIndex) or [stores](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/deleteObjectStore)

``` javascript

let additions = {
stores: [{
storeName: 'storeOne',
// optionally define a keyPath and/or set autoIncrement to true or false
options: { keyPath: "taskTitle" }
},
{
storeName: 'storeTwo'
}],
indexes: [{
indexName: 'newIndex',
keyPath: 'key',
// Any objectParameters for the Index
options: {
unique: false
}
}]
};

// Deletions is an optional parameter used to delete any indexes or stores
let deletions = {
stores: ['storeOne', 'storeTwo'],
indexes: ['newIndex']
};

// Optionally pass in the new database version. Set to true to increment the database version.
// Leave this parameter out or pass in false to connect without making any changes to the structure of the database
let dbVersion = 1

// The name of the database to connect to
let dbName = 'dbName';

// Finally, pass these parameters in to establish a connection with the database
savedData.onOpenDb(dbName, dbVersion, additions, deletions);
```

There are other methods currently supported to interact with the database. These allow you to [Add a record](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/add), [Delete a record](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/delete), [Read a record](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/get), or [Read all records](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/getAll). Each will return a success, or on failure, an error message

All the below methods accept a callback as a last parameter if you need to do something with the response.

``` javascript

//Delete a record by the key in a specific store
savedData.IDBRemove('storeName', 'key');

//add a record to a store. The record can be any type of object accepted by indexedDB
savedData.IDBAdd('storeName', 'record');

//returns the record with the given key from the store with the given storeName
savedData.IDBRead('storeName', 'key');

//Return all records from a database or optionally a specified amount defined by the second parameter
savedData.IDBReadAll('storeName');
savedData.IDBReadAll('storeName', 5);

// Return all keys in a given Index. [Docs](https://developer.mozilla.org/en-US/docs/Web/API/IDBIndex/getAllKeys)
// See [here](https://developer.mozilla.org/en-US/docs/Web/API/IDBKeyRange) for keyRange info
const keyRange = IDBKeyRange.bound("A", "F");
const count = 5;
savedData.IDBGetIndexKeys('storeName', 'indexName', query, 5);

// Finally, close the connection to the database
savedData.closeDb();

All other methods will work the same as the documentation [here](https://github.com/SpringRoll/SpringRoll/tree/main/src/state#userdata);

### SavedDataHandler
The SavedDataHandler class is used primarily in the `UserDataPlugin` to interact with the `SavedData` class. But can be used directly
if you require a callback when reading or writing from `SavedData`. Like `SavedData` all of the methods are static.

```javascript
import { SavedDataHandler } from 'springroll-container';

SavedDataHandler.write('user-value-name', 'value-to-be-stored', () => console.log('user-value-name written to storage'));

SavedDataHandler.read('user-value-name', value => console.log('Returned value: ' + value));

SavedDataHandler.remove('user-value-name', () => console.log('user-value-name removed from storage'));
```

We don't expect this handler to be used very often, but it is available if required.

### UserDataPlugin

This plugin allows the container to respond to requests from the Springroll Application's [User Data Class](https://github.com/SpringRoll/SpringRoll/tree/master/src/state).
It is included in the container constructor like any other plugin:

```javascript
import { UserDataPlugin, Container } from 'springroll-container';

const container = new Container('#game', {
plugins: [
new UserDataPlugin(),
]
});
container.openPath('game.html');
```

There is no configuration required for the UserDataPlugin as it just handles requests from the Application.

## License

Copyright (c) 2024 [SpringRoll](http://github.com/SpringRoll)
Expand Down
4 changes: 2 additions & 2 deletions dist/SpringRoll-Container-umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/SpringRoll-Container-umd.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

21 changes: 0 additions & 21 deletions e2e/e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
HelpPlugin,
PausePlugin,
SoundPlugin,
UserDataPlugin,
PointerSizePlugin,
ButtonSizePlugin,
LayersPlugin,
Expand Down Expand Up @@ -144,7 +143,6 @@ describe('End to End Test', () => {
voSliders: '#voSlider',
sfxSliders: '#sfxSlider'
});
const userDataPlugin = new UserDataPlugin();
const helpPlugin = new HelpPlugin('#helpButton');
const controlSensitivityPlugin = new ControlSensitivityPlugin('#sensitivitySlider');
keyboardMapPlugin = new KeyboardMapPlugin('#keyContainer');
Expand All @@ -170,7 +168,6 @@ describe('End to End Test', () => {
captionsStylePlugin,
pausePlugin,
soundPlugin,
userDataPlugin,
helpPlugin,
controlSensitivityPlugin,
keyboardMapPlugin,
Expand Down Expand Up @@ -317,22 +314,4 @@ describe('End to End Test', () => {
});
container.client.trigger('keepFocus');
});
it('userDataRemoved', done => {
container.client.on('userDataRemoved', () => {
done();
});
container.client.trigger('userDataRemoved');
});
it('userDataRead', done => {
container.client.on('userDataRead', () => {
done();
});
container.client.trigger('userDataRead');
});
it('userDataWrite', done => {
container.client.on('userDataWrite', () => {
done();
});
container.client.trigger('userDataWrite');
});
});
152 changes: 0 additions & 152 deletions src/SavedDataHandler.js

This file was deleted.

23 changes: 0 additions & 23 deletions src/SavedDataHandler.spec.js

This file was deleted.

Loading