mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
Adjust naming for promise-based callback functions in sources
This commit is contained in:
parent
c17685731a
commit
f8c923daec
@ -10,6 +10,7 @@ queryParams of the piece_list_store should all be reflected in the url and not a
|
||||
- Use classNames plugin instead of if-conditional-classes
|
||||
- Instead of using `currentUser && currentUser.email` in an validation that checks whether we user is logged in or now, in the `UserStore` on login we set a boolean property called `isLoggedIn` that can then be used instead of `email`
|
||||
- Refactor AclProxy to be a generic hide/show element component. Have it take data input and a validation function to assess whether it should show or hide child elements. Move current Acl checks to another place, eg. acl_utils.js.
|
||||
- Convert all fetchers to [alt.js's sources](http://alt.js.org/docs/async/)
|
||||
|
||||
# Refactor DONE
|
||||
- Refactor forms to generic-declarative form component ✓
|
||||
|
@ -10,7 +10,7 @@ class UserActions {
|
||||
'successFetchCurrentUser',
|
||||
'logoutCurrentUser',
|
||||
'successLogoutCurrentUser',
|
||||
'currentUserFailed'
|
||||
'errorCurrentUser'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ class WhitelabelActions {
|
||||
this.generateActions(
|
||||
'fetchWhitelabel',
|
||||
'successFetchWhitelabel',
|
||||
'whitelabelFailed'
|
||||
'errorWhitelabel'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
9
js/fetchers/README.md
Normal file
9
js/fetchers/README.md
Normal file
@ -0,0 +1,9 @@
|
||||
# README
|
||||
|
||||
Recently, we've been discovering [alt.js's sources](http://alt.js.org/docs/async/). As it allows us to implement caching as well as avoid a lot of unnecessary boilerplate code, we do not want to write any more NEW `fetcher`s.
|
||||
|
||||
So if you need to query an endpoint, or if you make active changes to one of the `fetcher`s, please consider refactoring it to a `source`.
|
||||
|
||||
Also, please read the `NAMING_CONVENTIONS.md` file in there first.
|
||||
|
||||
Thanks
|
@ -2,7 +2,7 @@
|
||||
|
||||
## Introduction
|
||||
|
||||
When using alt.js's sources, we don't want the source's method to clash with the store/action's method names.
|
||||
When using [alt.js's sources](http://alt.js.org/docs/async/), we don't want the source's method to clash with the store/action's method names.
|
||||
|
||||
While actions will still be named by the following schema:
|
||||
|
||||
@ -36,6 +36,7 @@ Therefore we're introducing the following naming convention:
|
||||
## Rules
|
||||
|
||||
1. All source methods that perform a data lookup of any kind (be it cached or not), are called `lookup<ObjectToManipulateInTheStore>`. As a mnemonic aid, "You *lookup* something in a *source*".
|
||||
2. Promise-based callback methods - provided by alt.js - prepend their action, followed by `ObjectToManipulateInTheStore` (e.g. `error<ObjectToManipulateInTheStore>`)
|
||||
2. For all methods that do not fit 1.), we prepend `perform`.
|
||||
|
||||
## Examples
|
||||
@ -50,6 +51,16 @@ UserSource.lookupCurrentUser
|
||||
```
|
||||
|
||||
### Examples for Rule 2.)
|
||||
This talks about the naming in an actual `*_source.js` file:
|
||||
|
||||
```javascript
|
||||
lookupCurrentUser: {
|
||||
success: UserActions.successFetchCurrentUser, // 'success<ObjectToManipulateInTheStore>'
|
||||
error: UserActions.errorCurrentUser, // 'error<ObjectToManipulateInTheStore>'
|
||||
},
|
||||
```
|
||||
|
||||
### Examples for Rule 3.)
|
||||
*HTTP GET'ing a certain user endpoint, that logs the user out :sad_face:(, as this should not be a GET request anyway)*
|
||||
|
||||
```javascript
|
||||
|
@ -16,7 +16,7 @@ const UserSource = {
|
||||
return state.currentUser && state.currentUser.email ? state : {};
|
||||
},
|
||||
success: UserActions.successFetchCurrentUser,
|
||||
error: UserActions.currentUserFailed,
|
||||
error: UserActions.errorCurrentUser,
|
||||
shouldFetch(state) {
|
||||
return state.userMeta.invalidateCache || state.currentUser && !state.currentUser.email;
|
||||
}
|
||||
@ -27,7 +27,7 @@ const UserSource = {
|
||||
return requests.get(ApiUrls.users_logout);
|
||||
},
|
||||
success: UserActions.successLogoutCurrentUser,
|
||||
error: UserActions.currentUserFailed
|
||||
error: UserActions.errorCurrentUser
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -15,7 +15,7 @@ const WhitelabelSource = {
|
||||
return Object.keys(state.whitelabel).length > 0 ? state : {};
|
||||
},
|
||||
success: WhitelabelActions.successFetchWhitelabel,
|
||||
error: WhitelabelActions.whitelabelFailed,
|
||||
error: WhitelabelActions.errorWhitelabel,
|
||||
shouldFetch(state) {
|
||||
return state.whitelabelMeta.invalidateCache || Object.keys(state.whitelabel).length === 0;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ class UserStore {
|
||||
this.currentUser = {};
|
||||
}
|
||||
|
||||
onCurrentUserFailed(err) {
|
||||
onErrorCurrentUser(err) {
|
||||
console.logGlobal(err);
|
||||
this.userMeta.err = err;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class WhitelabelStore {
|
||||
this.whitelabel = whitelabel;
|
||||
}
|
||||
|
||||
onWhitelabelFailed(err) {
|
||||
onErrorCurrentUser(err) {
|
||||
console.logGlobal(err);
|
||||
this.whitelabelMeta.err = err;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user