Skip to content

Commit

Permalink
Merge 2f719ac into 70d1b73
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienbarbier committed May 14, 2020
2 parents 70d1b73 + 2f719ac commit 85f9c5b
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ 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).


## [1.3.1] - 2020-05-11

### Added

- Special rule to expose `key` value on `GET_STORAGE_ITEM` event, with legacy support.

## [1.3.0] - 2020-05-06

### Added
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@
}
```

- Listenner

To listen `GET_STORAGE_ITEM`, ShellSdk provide a different syntax for legacy reason. You can access `value` and `key`
as following:
```typescript
sdk.on(SHELL_EVENTS.Version1.GET_STORAGE_ITEM, (value, key) => {
console.log(`${key} is now equal to ${value}`);
});
```

- #### V1.SET_STORAGE_ITEM
Save value in cloud staorage under specified key

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fsm-shell",
"version": "1.3.0",
"version": "1.3.1",
"description": "client library for FSM shell",
"main": "release/fsm-shell-client.js",
"module": "release/fsm-shell-client.es.js",
Expand Down
25 changes: 25 additions & 0 deletions src/ShellSdk.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,29 @@ describe('Shell Sdk', () => {
requestContext.resetHistory();
});

it('should have special syntax for GET_STORAGE_ITEM', (done) => {
const postMessageParent = sinon.spy();
sdk = ShellSdk.init({
postMessage: postMessageParent
} as any as Window, sdkOrigin, windowMock);

const requestContext = sinon.spy();

sdk.on(SHELL_EVENTS.Version1.GET_STORAGE_ITEM, (value, key) => {
expect(value).toBe('fr');
expect(key).toBe('Cockpit_SelectedLocale');
done();
});

windowMockCallback({
data: {
type: SHELL_EVENTS.Version1.GET_STORAGE_ITEM,
value: {
key: 'Cockpit_SelectedLocale',
value: 'fr'
}
}
});
});

});
20 changes: 15 additions & 5 deletions src/ShellSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,21 @@ export class ShellSdk {

if (!!subscribers) {
for (const subscriber of subscribers) {
subscriber(
payload.value,
event.origin,
payload.type == SHELL_EVENTS.Version1.SET_VIEW_STATE ? null : payload.from
);
if (payload.type == SHELL_EVENTS.Version1.GET_STORAGE_ITEM) {
// different call for GET_STORAGE_ITEM to support legacy code (CPB-47059)
subscriber(
payload.value.value,
payload.value.key,
event.origin,
payload.from
);
} else {
subscriber(
payload.value,
event.origin,
payload.type == SHELL_EVENTS.Version1.SET_VIEW_STATE ? null : payload.from
);
}
}
}

Expand Down

0 comments on commit 85f9c5b

Please sign in to comment.