Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
af20c442
Commit
af20c442
authored
Mar 28, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor ADD_PENDING_TAB to stop multiple state changes
parent
c5a591e6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
43 deletions
+26
-43
app/assets/javascripts/ide/stores/actions/file.js
app/assets/javascripts/ide/stores/actions/file.js
+1
-1
app/assets/javascripts/ide/stores/mutations/file.js
app/assets/javascripts/ide/stores/mutations/file.js
+21
-38
spec/javascripts/ide/stores/mutations/file_spec.js
spec/javascripts/ide/stores/mutations/file_spec.js
+4
-4
No files found.
app/assets/javascripts/ide/stores/actions/file.js
View file @
af20c442
...
@@ -143,7 +143,7 @@ export const openPendingTab = ({ commit, getters, dispatch, state }, file) => {
...
@@ -143,7 +143,7 @@ export const openPendingTab = ({ commit, getters, dispatch, state }, file) => {
return
false
;
return
false
;
}
}
commit
(
types
.
ADD_PENDING_TAB
,
file
);
commit
(
types
.
ADD_PENDING_TAB
,
{
file
}
);
dispatch
(
'
scrollToTab
'
);
dispatch
(
'
scrollToTab
'
);
...
...
app/assets/javascripts/ide/stores/mutations/file.js
View file @
af20c442
...
@@ -96,50 +96,33 @@ export default {
...
@@ -96,50 +96,33 @@ export default {
changed
,
changed
,
});
});
},
},
[
types
.
ADD_PENDING_TAB
](
state
,
file
)
{
[
types
.
ADD_PENDING_TAB
](
state
,
{
file
,
keyPrefix
=
'
pending
'
}
)
{
const
pendingTab
=
state
.
openFiles
.
find
(
f
=>
f
.
path
===
file
.
path
&&
f
.
pending
);
const
pendingTab
=
state
.
openFiles
.
find
(
f
=>
f
.
path
===
file
.
path
&&
f
.
pending
);
let
openFiles
=
state
.
openFiles
.
map
(
f
=>
Object
.
assign
(
f
,
{
active
:
f
.
path
===
file
.
path
,
opened
:
false
}),
);
Object
.
assign
(
state
,
{
if
(
!
pendingTab
)
{
openFiles
:
state
.
openFiles
.
map
(
f
=>
Object
.
assign
(
f
,
{
active
:
false
})),
const
openFile
=
openFiles
.
find
(
f
=>
f
.
path
===
file
.
path
);
});
if
(
pendingTab
)
{
openFiles
=
openFiles
.
concat
(
openFile
?
null
:
file
).
reduce
((
acc
,
f
)
=>
{
Object
.
assign
(
state
,
{
if
(
!
f
)
return
acc
;
openFiles
:
state
.
openFiles
.
map
(
f
=>
{
if
(
f
.
pending
&&
f
.
path
===
file
.
path
)
{
return
Object
.
assign
(
f
,
{
active
:
true
});
}
return
f
;
}),
});
}
else
{
const
openFile
=
state
.
openFiles
.
find
(
f
=>
f
.
path
===
file
.
path
);
const
openFiles
=
state
.
openFiles
.
concat
(
openFile
?
null
:
file
)
.
filter
(
f
=>
f
)
.
reduce
((
acc
,
f
)
=>
{
if
(
f
.
path
===
file
.
path
)
{
if
(
f
.
path
===
file
.
path
)
{
return
acc
.
concat
({
return
acc
.
concat
({
...
f
,
...
f
,
active
:
true
,
active
:
true
,
pending
:
true
,
pending
:
true
,
key
:
`pending-
${
f
.
key
}
`
,
opened
:
true
,
key
:
`
${
keyPrefix
}
-
${
f
.
key
}
`
,
});
});
}
}
return
acc
.
concat
(
f
);
return
acc
.
concat
(
f
);
},
[]);
},
[]);
Object
.
assign
(
state
,
{
entries
:
Object
.
assign
(
state
.
entries
,
{
[
file
.
path
]:
Object
.
assign
(
state
.
entries
[
file
.
path
],
{
opened
:
false
,
}),
}),
openFiles
,
});
}
}
Object
.
assign
(
state
,
{
openFiles
});
},
},
[
types
.
REMOVE_PENDING_TAB
](
state
,
file
)
{
[
types
.
REMOVE_PENDING_TAB
](
state
,
file
)
{
Object
.
assign
(
state
,
{
Object
.
assign
(
state
,
{
...
...
spec/javascripts/ide/stores/mutations/file_spec.js
View file @
af20c442
...
@@ -183,7 +183,7 @@ describe('Multi-file store file mutations', () => {
...
@@ -183,7 +183,7 @@ describe('Multi-file store file mutations', () => {
});
});
it
(
'
adds file into openFiles as pending
'
,
()
=>
{
it
(
'
adds file into openFiles as pending
'
,
()
=>
{
mutations
.
ADD_PENDING_TAB
(
localState
,
localFile
);
mutations
.
ADD_PENDING_TAB
(
localState
,
{
file
:
localFile
}
);
expect
(
localState
.
openFiles
.
length
).
toBe
(
2
);
expect
(
localState
.
openFiles
.
length
).
toBe
(
2
);
expect
(
localState
.
openFiles
[
1
].
pending
).
toBe
(
true
);
expect
(
localState
.
openFiles
[
1
].
pending
).
toBe
(
true
);
...
@@ -191,7 +191,7 @@ describe('Multi-file store file mutations', () => {
...
@@ -191,7 +191,7 @@ describe('Multi-file store file mutations', () => {
});
});
it
(
'
updates open file to pending
'
,
()
=>
{
it
(
'
updates open file to pending
'
,
()
=>
{
mutations
.
ADD_PENDING_TAB
(
localState
,
localState
.
openFiles
[
0
]
);
mutations
.
ADD_PENDING_TAB
(
localState
,
{
file
:
localState
.
openFiles
[
0
]
}
);
expect
(
localState
.
openFiles
.
length
).
toBe
(
1
);
expect
(
localState
.
openFiles
.
length
).
toBe
(
1
);
});
});
...
@@ -202,14 +202,14 @@ describe('Multi-file store file mutations', () => {
...
@@ -202,14 +202,14 @@ describe('Multi-file store file mutations', () => {
pending
:
true
,
pending
:
true
,
});
});
mutations
.
ADD_PENDING_TAB
(
localState
,
localFile
);
mutations
.
ADD_PENDING_TAB
(
localState
,
{
file
:
localFile
}
);
expect
(
localState
.
openFiles
[
1
].
pending
).
toBe
(
true
);
expect
(
localState
.
openFiles
[
1
].
pending
).
toBe
(
true
);
expect
(
localState
.
openFiles
[
1
].
active
).
toBe
(
true
);
expect
(
localState
.
openFiles
[
1
].
active
).
toBe
(
true
);
});
});
it
(
'
sets all openFiles to not active
'
,
()
=>
{
it
(
'
sets all openFiles to not active
'
,
()
=>
{
mutations
.
ADD_PENDING_TAB
(
localState
,
localFile
);
mutations
.
ADD_PENDING_TAB
(
localState
,
{
file
:
localFile
}
);
expect
(
localState
.
openFiles
.
length
).
toBe
(
2
);
expect
(
localState
.
openFiles
.
length
).
toBe
(
2
);
...
...
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