-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrap SiteWise Asset related API calls in a Data Source #25
Conversation
@@ -1,4 +1,4 @@ | |||
import { BehaviorSubject, Observable, Subscription } from 'rxjs'; | |||
import { Observable, ReplaySubject, Subscription } from 'rxjs'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are you using ReplaySubject here? From the documentation I see it is used to record a history of previous values but I don't see that being used here. I think I am missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think I missed the part that by default it will return all the previous values if no buffer is provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call out! I only want it to replay the latest value. I can get that with ReplaySubject(1)
branches: 60, | ||
functions: 70, | ||
lines: 75, | ||
statements: 80, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
|
||
it('waits for the AssetSummary', done => { | ||
observable.subscribe(result => { | ||
expect(result).not.toBeUndefined(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: do we need this assertion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weirdly, yes. I spent the better part of a day debugging the tests only to find out that I was comparing undefined to undefined and getting passing tests when they should have failed.
@@ -102,6 +113,14 @@ type SubscribeToDataStreamsFromPrivate = ( | |||
unsubscribe: () => void; | |||
}; | |||
|
|||
export type SiteWiseAssetDataSource = { | |||
describeAsset: (input: DescribeAssetCommandInput) => Promise<DescribeAssetCommandOutput>; | |||
getPropertyValue: (input: GetAssetPropertyValueCommandInput) => Promise<GetAssetPropertyValueCommandOutput>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the data module to get asset property value? https://github.com/awslabs/iot-app-kit/blob/main/packages/core/src/data-sources/site-wise/client/getLatestPropertyDataPoint.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version in the assets code treats all values as if they are attributes, i.e. they do not update over time (this avoids re-requesting things that shouldn't actually change).
error?: ((error: any) => void) | null, | ||
complete?: (() => void) | null | ||
): Subscription { | ||
throw "deprecated, use addObserver"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addSubscriber
e821596
to
1c45760
Compare
let timeoutID: any; | ||
let counter = 0; | ||
return new Observable<number>((subscriber) => { | ||
timeoutID = setTimeout(function incramenter() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: incrementer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doh!
timeoutID = setTimeout(function incramenter() { | ||
counter++; | ||
subscriber.next(counter); | ||
timeoutID = setTimeout(incramenter, 5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: instead of recursion could just be setInterval
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh, totally forgot about that, will change.
* Release 1.2.1 (#85) * fix: unsubrscribe data provider on component updates * Release 1.2.1 Co-authored-by: Norbert Nader <nnader@amazon.com> * fix: resolves #83 (#87) * fix: resolves #83 * Update index.ts Co-authored-by: Norbert Nader <nnader@amazon.com> * feat: improve documentation (#90) * Run tests on pull request (#91) * Update reference to code name (#86) AWS-UI internal code name is mentioned in the readme. Co-authored-by: Norbert Nader <Norbert.Nader@gmail.com> * feat: update synchro charts to 3.1.0, update docs (#92) * feat: Improve documentation formatting (#93) * feat: Improve resource explorer docs (#95) * Update README.md (#94) * feat: support fetchMostRecentBeforeStart (#79) * Update documentation & make react-components easier to use (#98) * Utilize lock file in CI (#99) * build(deps): bump async from 2.6.3 to 2.6.4 (#100) Bumps [async](https://github.com/caolan/async) from 2.6.3 to 2.6.4. - [Release notes](https://github.com/caolan/async/releases) - [Changelog](https://github.com/caolan/async/blob/v2.6.4/CHANGELOG.md) - [Commits](caolan/async@v2.6.3...v2.6.4) --- updated-dependencies: - dependency-name: async dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat: support auto-assigning colors for certain components (#96) * feat: support auto-assigning colors for certain components * Update package.json * Update cypress to v9, added stricted linting, fixed linting warnings and errors (#104) * Add stylelint and enforce via global package.json (#106) * use most recent synchro-charts version, 4.0.1 (#111) * build(deps): bump eventsource from 1.1.0 to 1.1.1 (#116) Bumps [eventsource](https://github.com/EventSource/eventsource) from 1.1.0 to 1.1.1. - [Release notes](https://github.com/EventSource/eventsource/releases) - [Changelog](https://github.com/EventSource/eventsource/blob/master/HISTORY.md) - [Commits](EventSource/eventsource@v1.1.0...v1.1.1) --- updated-dependencies: - dependency-name: eventsource dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat: expand children in resource explorer (#115) * feat: expand children in resource explorer * fix typo * Fix asset module cache * Add logic for fetching hierarchies * Add tests * Improve insert * Fix linting Co-authored-by: Norbert Nader <nnader@amazon.com> * Update README.md (#121) Fix test runner status badge * Bump minor version (#120) * specify react types package version to be 17 (#134) Co-authored-by: Xinyi <xinyxu@amazon.com> * build(deps): bump parse-url from 6.0.0 to 6.0.2 (#142) Bumps [parse-url](https://github.com/IonicaBizau/parse-url) from 6.0.0 to 6.0.2. - [Release notes](https://github.com/IonicaBizau/parse-url/releases) - [Commits](https://github.com/IonicaBizau/parse-url/commits) --- updated-dependencies: - dependency-name: parse-url dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Fix: Development Quick Start Docs/Scripts (#148) * add yarn bootstrap script to replace lerna bootstrap * specify supported node and yarn engines * simplify development docs and update build steps Co-authored-by: Thomas Juranek <thjurane@amazon.com> * build(deps): bump moment from 2.29.2 to 2.29.4 (#149) Bumps [moment](https://github.com/moment/moment) from 2.29.2 to 2.29.4. - [Release notes](https://github.com/moment/moment/releases) - [Changelog](https://github.com/moment/moment/blob/develop/CHANGELOG.md) - [Commits](moment/moment@2.29.2...2.29.4) --- updated-dependencies: - dependency-name: moment dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: update @testing-library/react to use create root (#151) Co-authored-by: Norbert Nader <Norbert.Nader@gmail.com> * feat(props): adapt props for synchro-charts (#133) * feat(props): adapt props for synchro-charts * add testing for new props * fix(tests): cleanup tests from devwork * Update changelog * update tests to wait for intercepts Co-authored-by: Norbert Nader <Norbert.Nader@gmail.com> * feat: batch API for historical, aggregated, and latest value data (#137) * fix: resolve float decimal precision issue on round() function. (#160) * fix: update @testing-library/react to use create root * fix: resolve float decimal precision issue on round() function. * Simplify round() function. Remove managing the negative sign separately. Co-authored-by: Norbert Nader <Norbert.Nader@gmail.com> * sync changes with private repo for common files (#150) * sync changes with private repo for common files * Revert "fix: update @testing-library/react to use create root (#151)" This reverts commit 960f53f. Co-authored-by: Xinyi <xinyxu@amazon.com> * Update npm packages repository (#161) * build(deps): bump terser from 4.8.0 to 4.8.1 (#168) Bumps [terser](https://github.com/terser/terser) from 4.8.0 to 4.8.1. - [Release notes](https://github.com/terser/terser/releases) - [Changelog](https://github.com/terser/terser/blob/master/CHANGELOG.md) - [Commits](https://github.com/terser/terser/commits) --- updated-dependencies: - dependency-name: terser dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * remove node version requirement for now until switched internal package to v16 Co-authored-by: Norbert Nader <Norbert.Nader@gmail.com> Co-authored-by: Norbert Nader <nnader@amazon.com> Co-authored-by: db <77755322+diehbria@users.noreply.github.com> Co-authored-by: Mitchell Lee <mitch@evildev.net> Co-authored-by: Bowei Han <boweih@amazon.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Xinyi Xu <sheilaxxy@gmail.com> Co-authored-by: Xinyi <xinyxu@amazon.com> Co-authored-by: Thomas Juranek <thomas@juranek.com> Co-authored-by: Thomas Juranek <thjurane@amazon.com> Co-authored-by: Xiao(Bill) Li <limxiao@amazon.com> Co-authored-by: jmbuss <107281089+jmbuss@users.noreply.github.com>
Overview
DataSource
for SiteWise assets module to use. This scopes down what the asset modules can get at from the raw API.RequestProcessor
RequestProcessWorker
toReplaySubject
. This stops an initial 'empty' value from being set to the caller which could be confusing and make programming more complex for the non-list use-case.RequestProcessorWorkerGroup
for every request inRequestProcessor
, not any simultaneous requests for the same data item will result in only 1 API call.Tests
Legal
This project is available under the Apache 2.0 License.