Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
ThaliApp
Commits
942d353a
Commit
942d353a
authored
Mar 15, 2017
by
Wietse Kuipers
Browse files
Small refactor to improve readability
parent
64b4b83a
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/app.js
View file @
942d353a
import
React
,
{
Component
}
from
'
react
'
;
import
{
BackAndroid
,
AsyncStorage
}
from
'
react-native
'
;
import
{
AsyncStorage
}
from
'
react-native
'
;
import
{
createStore
,
applyMiddleware
,
combineReducers
}
from
'
redux
'
;
import
{
Provider
}
from
'
react-redux
'
;
import
thunk
from
'
redux-thunk
'
;
import
*
as
reducers
from
'
./reducers
'
;
import
ReduxNavigator
from
'
./components/navigator
'
;
import
{
back
}
from
'
./actions/navigation
'
;
import
{
initLogin
}
from
'
./actions/login
'
;
const
createStoreWithMiddleware
=
applyMiddleware
(
thunk
)(
createStore
);
...
...
@@ -15,27 +14,18 @@ const store = createStoreWithMiddleware(reducer);
const
USERNAMEKEY
=
'
@MyStore:username
'
;
const
TOKENKEY
=
'
@MyStore:token
'
;
BackAndroid
.
addEventListener
(
'
hardwareBackPress
'
,
()
=>
{
if
(
store
.
getState
().
navigation
.
previousScenes
.
length
===
0
)
{
return
false
;
}
store
.
dispatch
(
back
());
return
true
;
});
const
pairsToObject
=
(
obj
,
pair
)
=>
{
const
obj2
=
{
...
obj
};
obj2
[
pair
[
0
]]
=
pair
[
1
];
return
obj2
;
};
class
Main
extends
Component
{
componentDidMount
()
{
AsyncStorage
.
multiGet
([
USERNAMEKEY
,
TOKENKEY
])
.
then
(
(
result
)
=>
{
// Transform [key, value] pairs into object, for easier access
const
values
=
result
.
reduce
((
obj
,
pair
)
=>
{
const
obj2
=
{
...
obj
};
obj2
[
pair
[
0
]]
=
pair
[
1
];
return
obj2
;
},
{});
const
values
=
result
.
reduce
(
pairsToObject
,
{});
const
username
=
values
[
USERNAMEKEY
];
const
token
=
values
[
TOKENKEY
];
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment