Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
Hubs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ar-noc
Hubs
Commits
673a7f44
Commit
673a7f44
authored
7 years ago
by
Greg Fodor
Browse files
Options
Downloads
Patches
Plain Diff
Feedback from PR
parent
47f21a6e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/react-components/profile-entry-panel.js
+2
-2
2 additions, 2 deletions
src/react-components/profile-entry-panel.js
src/storage/store.js
+7
-17
7 additions, 17 deletions
src/storage/store.js
with
9 additions
and
19 deletions
src/react-components/profile-entry-panel.js
+
2
−
2
View file @
673a7f44
...
@@ -14,7 +14,7 @@ class ProfileEntryPanel extends Component {
...
@@ -14,7 +14,7 @@ class ProfileEntryPanel extends Component {
super
(
props
);
super
(
props
);
window
.
store
=
this
.
props
.
store
;
window
.
store
=
this
.
props
.
store
;
this
.
state
=
{
name
:
this
.
props
.
store
.
state
.
profile
.
display_name
};
this
.
state
=
{
name
:
this
.
props
.
store
.
state
.
profile
.
display_name
};
this
.
props
.
store
.
subscribe
(
this
.
storeUpdated
);
this
.
props
.
store
.
addEventListener
(
"
statechanged
"
,
this
.
storeUpdated
);
}
}
storeUpdated
=
()
=>
{
storeUpdated
=
()
=>
{
...
@@ -35,7 +35,7 @@ class ProfileEntryPanel extends Component {
...
@@ -35,7 +35,7 @@ class ProfileEntryPanel extends Component {
}
}
componentWillUnmount
()
{
componentWillUnmount
()
{
this
.
props
.
store
.
unsubscribe
(
this
.
storeUpdated
);
this
.
props
.
store
.
removeEventListener
(
'
statechanged
'
,
this
.
storeUpdated
);
}
}
render
()
{
render
()
{
...
...
This diff is collapsed.
Click to expand it.
src/storage/store.js
+
7
−
17
View file @
673a7f44
...
@@ -4,6 +4,7 @@ import { Validator } from "jsonschema";
...
@@ -4,6 +4,7 @@ import { Validator } from "jsonschema";
const
LOCAL_STORE_KEY
=
"
___mozilla_duck
"
;
const
LOCAL_STORE_KEY
=
"
___mozilla_duck
"
;
const
STORE_STATE_CACHE_KEY
=
Symbol
();
const
STORE_STATE_CACHE_KEY
=
Symbol
();
const
validator
=
new
Validator
();
const
validator
=
new
Validator
();
import
{
EventTarget
}
from
"
event-target-shim
"
// Durable (via local-storage) schema-enforced state that is meant to be consumed via forward data flow.
// Durable (via local-storage) schema-enforced state that is meant to be consumed via forward data flow.
// (Think flux but with way less incidental complexity, at least for now :))
// (Think flux but with way less incidental complexity, at least for now :))
...
@@ -30,10 +31,10 @@ export const SCHEMA = {
...
@@ -30,10 +31,10 @@ export const SCHEMA = {
additionalProperties
:
false
additionalProperties
:
false
}
}
export
default
class
Store
{
export
default
class
Store
extends
EventTarget
{
subscribers
=
new
Set
();
constructor
()
{
constructor
()
{
super
();
if
(
localStorage
.
getItem
(
LOCAL_STORE_KEY
)
===
null
)
{
if
(
localStorage
.
getItem
(
LOCAL_STORE_KEY
)
===
null
)
{
localStorage
.
setItem
(
LOCAL_STORE_KEY
,
JSON
.
stringify
({
id
:
uuid
()
}));
localStorage
.
setItem
(
LOCAL_STORE_KEY
,
JSON
.
stringify
({
id
:
uuid
()
}));
}
}
...
@@ -47,34 +48,23 @@ export default class Store {
...
@@ -47,34 +48,23 @@ export default class Store {
return
this
[
STORE_STATE_CACHE_KEY
];
return
this
[
STORE_STATE_CACHE_KEY
];
}
}
subscribe
(
subscriber
)
{
this
.
subscribers
.
add
(
subscriber
);
}
unsubscribe
(
subscriber
)
{
this
.
subscribers
.
delete
(
subscriber
);
}
update
(
newState
)
{
update
(
newState
)
{
if
(
newState
.
id
)
{
if
(
newState
.
id
)
{
console
.
error
(
"
Store id is immutable.
"
);
throw
"
Store id is immutable.
"
;
return
;
}
}
const
finalState
=
{
...
this
.
state
,
...
newState
};
const
finalState
=
{
...
this
.
state
,
...
newState
};
const
isValid
=
validator
.
validate
(
finalState
,
SCHEMA
).
valid
;
const
isValid
=
validator
.
validate
(
finalState
,
SCHEMA
).
valid
;
if
(
!
isValid
)
{
if
(
!
isValid
)
{
console
.
warn
(
`Write of
${
JSON
.
stringify
(
finalState
)}
to store failed schema validation.`
)
throw
`Write of
${
JSON
.
stringify
(
finalState
)}
to store failed schema validation.`
;
return
;
return
;
}
}
localStorage
.
setItem
(
LOCAL_STORE_KEY
,
JSON
.
stringify
(
finalState
));
localStorage
.
setItem
(
LOCAL_STORE_KEY
,
JSON
.
stringify
(
finalState
));
delete
this
[
STORE_STATE_CACHE_KEY
];
delete
this
[
STORE_STATE_CACHE_KEY
];
for
(
const
subscriber
of
this
.
subscribers
)
{
this
.
dispatchEvent
(
new
CustomEvent
(
"
statechanged
"
));
subscriber
();
}
return
finalState
;
return
finalState
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment