Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
62891a13
Commit
62891a13
authored
Mar 28, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Mar 30, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate features module to TypeScript
parent
32ddd01d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
27 deletions
+14
-27
features.ts
src/annotator/features.ts
+14
-27
No files found.
src/annotator/features.
j
s
→
src/annotator/features.
t
s
View file @
62891a13
import
{
TinyEmitter
}
from
'tiny-emitter'
;
import
{
warnOnce
}
from
'../shared/warn-once'
;
/**
* @typedef {import('../types/annotator').FeatureFlags} IFeatureFlags
*/
import
type
{
FeatureFlags
as
IFeatureFlags
}
from
'../types/annotator'
;
/**
* List of feature flags that annotator code tests for.
*
* @type {string[]}
*/
const
annotatorFlags
=
[
'html_side_by_side'
,
'styled_highlight_clusters'
];
/**
* An observable container of feature flags.
*
* @implements {IFeatureFlags}
*/
export
class
FeatureFlags
extends
TinyEmitter
{
export
class
FeatureFlags
extends
TinyEmitter
implements
IFeatureFlags
{
/** Map of flag name to enabled state. */
private
_flags
:
Map
<
string
,
boolean
>
;
private
_knownFlags
:
string
[];
/**
* @param
{string[]} knownFlags - Test seam. This is a list of known flags
*
used to catch
mistakes where code checks for an obsolete feature flag.
* @param
knownFlags - Test seam. This is a list of known flags used to catch
*
mistakes where code checks for an obsolete feature flag.
*/
constructor
(
knownFlags
=
annotatorFlags
)
{
constructor
(
knownFlags
:
string
[]
=
annotatorFlags
)
{
super
();
/**
* Map of flag name to enabled state.
*
* @type {Map<string, boolean>}
*/
this
.
_flags
=
new
Map
();
this
.
_flags
=
new
Map
<
string
,
boolean
>
();
this
.
_knownFlags
=
knownFlags
;
}
/**
* Update the stored flags and notify observers via a "flagsChanged" event.
*
* @param {Record<string, boolean>} flags
*/
update
(
flags
)
{
update
(
flags
:
Record
<
string
,
boolean
>
)
{
this
.
_flags
.
clear
();
for
(
le
t
[
flag
,
on
]
of
Object
.
entries
(
flags
))
{
for
(
cons
t
[
flag
,
on
]
of
Object
.
entries
(
flags
))
{
this
.
_flags
.
set
(
flag
,
on
);
}
this
.
emit
(
'flagsChanged'
);
...
...
@@ -54,11 +44,8 @@ export class FeatureFlags extends TinyEmitter {
* This will return false if the feature flags have not yet been received from
* the backend. Code that uses a feature flag should handle subsequent changes
* to the flag's state by listening for the "flagsChanged" event.
*
* @param {string} flag
* @return {boolean}
*/
flagEnabled
(
flag
)
{
flagEnabled
(
flag
:
string
):
boolean
{
if
(
!
this
.
_knownFlags
.
includes
(
flag
))
{
warnOnce
(
'Looked up unknown feature'
,
flag
);
return
false
;
...
...
@@ -72,7 +59,7 @@ export class FeatureFlags extends TinyEmitter {
* To test whether an individual flag is enabled, use {@link flagEnabled}
* instead.
*/
allFlags
()
{
allFlags
()
:
Record
<
string
,
boolean
>
{
return
Object
.
fromEntries
(
this
.
_flags
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment