-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle multiple concurrent request (#164)
- Loading branch information
Showing
4 changed files
with
68 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import {Constructor} from './utils'; | ||
import {property} from 'lit/decorators.js'; | ||
import {LitElement} from 'lit'; | ||
|
||
export interface VersioningMixinInterface { | ||
version: number; | ||
incrementVersion(): number; | ||
isLatestVersion(version: number): boolean; | ||
} | ||
export const VersioningMixin = <T extends Constructor<LitElement>>( | ||
superClass: T | ||
) => { | ||
/** | ||
* The mixin encapsulate the versioning logic | ||
* It allows to avoid updating the data with older responses | ||
*/ | ||
class VersioningMixinClass extends superClass { | ||
/** | ||
* The version of the object | ||
*/ | ||
@property({attribute: false}) | ||
version = 0; | ||
|
||
/** | ||
* Increment the version of the object | ||
*/ | ||
incrementVersion() { | ||
this.version++; | ||
return this.version; | ||
} | ||
|
||
/** | ||
* Check if the version is the latest | ||
*/ | ||
isLatestVersion(version: number) { | ||
return version === this.version; | ||
} | ||
} | ||
|
||
return VersioningMixinClass as Constructor<VersioningMixinInterface> & T; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters