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
fee80c6d
Unverified
Commit
fee80c6d
authored
Aug 21, 2019
by
Robert Knight
Committed by
GitHub
Aug 21, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1314 from hypothesis/namespace-drafts-module
Namespace the drafts module
parents
1e62dac0
4e09c599
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
18 deletions
+12
-18
drafts.js
src/sidebar/store/modules/drafts.js
+12
-18
No files found.
src/sidebar/store/modules/drafts.js
View file @
fee80c6d
...
@@ -9,9 +9,7 @@ const util = require('../util');
...
@@ -9,9 +9,7 @@ const util = require('../util');
*/
*/
function
init
()
{
function
init
()
{
return
{
return
[];
drafts
:
[],
};
}
}
/**
/**
...
@@ -58,27 +56,21 @@ class Draft {
...
@@ -58,27 +56,21 @@ class Draft {
const
update
=
{
const
update
=
{
DISCARD_ALL_DRAFTS
:
function
()
{
DISCARD_ALL_DRAFTS
:
function
()
{
return
{
return
[];
drafts
:
[],
};
},
},
REMOVE_DRAFT
:
function
(
state
,
action
)
{
REMOVE_DRAFT
:
function
(
state
,
action
)
{
const
drafts
=
state
.
drafts
.
filter
(
draft
=>
{
const
drafts
=
state
.
filter
(
draft
=>
{
return
!
draft
.
match
(
action
.
annotation
);
return
!
draft
.
match
(
action
.
annotation
);
});
});
return
{
return
drafts
;
drafts
,
};
},
},
UPDATE_DRAFT
:
function
(
state
,
action
)
{
UPDATE_DRAFT
:
function
(
state
,
action
)
{
// removes a matching existing draft, then adds
// removes a matching existing draft, then adds
const
drafts
=
state
.
drafts
.
filter
(
draft
=>
{
const
drafts
=
state
.
filter
(
draft
=>
{
return
!
draft
.
match
(
action
.
draft
.
annotation
);
return
!
draft
.
match
(
action
.
draft
.
annotation
);
});
});
drafts
.
push
(
action
.
draft
);
// push ok since its a copy
drafts
.
push
(
action
.
draft
);
// push ok since its a copy
return
{
return
drafts
;
drafts
,
};
},
},
};
};
...
@@ -106,10 +98,10 @@ function createDraft(annotation, changes) {
...
@@ -106,10 +98,10 @@ function createDraft(annotation, changes) {
function
deleteNewAndEmptyDrafts
()
{
function
deleteNewAndEmptyDrafts
()
{
const
annotations
=
require
(
'./annotations'
);
const
annotations
=
require
(
'./annotations'
);
return
(
dispatch
,
getState
)
=>
{
return
(
dispatch
,
getState
)
=>
{
const
newDrafts
=
getState
().
base
.
drafts
.
filter
(
draft
=>
{
const
newDrafts
=
getState
().
drafts
.
filter
(
draft
=>
{
return
(
return
(
metadata
.
isNew
(
draft
.
annotation
)
&&
metadata
.
isNew
(
draft
.
annotation
)
&&
!
getDraftIfNotEmpty
(
getState
()
.
base
,
draft
.
annotation
)
!
getDraftIfNotEmpty
(
getState
(),
draft
.
annotation
)
);
);
});
});
const
removedAnnotations
=
newDrafts
.
map
(
draft
=>
{
const
removedAnnotations
=
newDrafts
.
map
(
draft
=>
{
...
@@ -157,8 +149,9 @@ function countDrafts(state) {
...
@@ -157,8 +149,9 @@ function countDrafts(state) {
* @return {Draft|null}
* @return {Draft|null}
*/
*/
function
getDraft
(
state
,
annotation
)
{
function
getDraft
(
state
,
annotation
)
{
for
(
let
i
=
0
;
i
<
state
.
drafts
.
length
;
i
++
)
{
const
drafts
=
state
.
drafts
;
const
draft
=
state
.
drafts
[
i
];
for
(
let
i
=
0
;
i
<
drafts
.
length
;
i
++
)
{
const
draft
=
drafts
[
i
];
if
(
draft
.
match
(
annotation
))
{
if
(
draft
.
match
(
annotation
))
{
return
draft
;
return
draft
;
}
}
...
@@ -194,6 +187,7 @@ function unsavedAnnotations(state) {
...
@@ -194,6 +187,7 @@ function unsavedAnnotations(state) {
module
.
exports
=
{
module
.
exports
=
{
init
,
init
,
namespace
:
'drafts'
,
update
,
update
,
actions
:
{
actions
:
{
createDraft
,
createDraft
,
...
...
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