-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/resource builder #2
Conversation
…generator and fetch feature
b77ae10
to
1e57d17
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Il manque des explication afin de comprendre ta vision des choses sur comment utiliser chaque Builder.
Pas mal d'accro avec le code style (essaye de lancer ./node_modules/.bin.eslint --fix src/
pour précorriger et sans le --fix
pour voir les autres problèmes)
Et il manque pas mal de commentaire sur les méthode de class :(
README.md
Outdated
|
||
# TODO | ||
[draft] | ||
- think to add fetch polyfill |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je ne pense pas que ce soit necessaire, je pense qu'il faut plus préciser à l'utilisateur de le faire lui même s'il veut que ça fonctionne.
Raison : Si le dev a déjà installé le polyfill, on risque d'alourdir inutilement le package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c'est ton code à toi que j'avais repris ça lol
Pour les method private elle doivent être préfixé par un underscore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Le mieux est d'éviter au max d'utiliser lodash qui est plus lourd et moins optimiser (et j'aime pas leurs fonction, elles veulent rien dire à se qu'elle font)
}; | ||
}; | ||
|
||
/* eslint-disable no-param-reassign */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pourquoi ne pas transformer cette fonction en méthode privée ? 🤔 ça évitera une fonction qui fait des mutations sur ces propres valeurs d'entrée
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pour l'instant je pensais laisser ça en méthode un peu bordel parce que je suis pas trop sur de savoir a quel point je vais pouvoir réutiliser, si il faut que je modifie l'interface ou pas...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Le pb c'est que j'utilise pas de this. Je vais essayer de tricher mais perso je trouve ça très dégueu, ça me forcerait sinon à faire des this[iVarName]
if (isArray(a)) { | ||
return a.concat(b); | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Il manque un return par défaut
y'a un ;
après le if qui est inutile
Pourquoi ne pas le mettre dans un utils ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://lodash.com/docs/4.17.10#mergeWith.
If customizer returns undefined, merging is handled by the method instead
return mergeWith( | ||
{}, this.sideposts, this.associations, this.disassociations, | ||
concatNestedArrayCustomizer, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pourquoi ne pas simplement faire un
return ({
...this.sideposts,
...this.associations,
...this.disassociations
});
this.sideposts, | ||
concatNestedArrayCustomizer | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pareil que au-dessus
action() { | ||
this.ensureReadyToPerform(); | ||
return ({ | ||
type: requestActionType( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go utiliser les fonction dans utils/actions.js
|
||
/* @api private */ | ||
get requestActionTypePrefix() { | ||
return 'READ'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Le problème avec ça c'est qu'on peut pas savoir si c'est un READ ou un READ_LIST :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attention, différence entre ResourceReader
et ResourcesReader
with an s
. Mais sinon on peut refacto en ResourceListReader
pour éviter les wtf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah lol en fait j'ai pas encore codé ça de tt façon
06131ab
to
096bc51
Compare
Implemented review and added missing code related to URL generation
d42211f
to
00c099e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing Delete method ? + missing many comments
|
||
```javascript | ||
employeeReader = new JsonapiResourceReader({ type: 'employee'}) | ||
employeeReader.sideload({ company: { admins: true } }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No possibilities to pass an array of string ? (like : ['company.admin', 'profil']
) to be more flexible with sideloading building
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.sideload({ company: { admins: true }, profile: true })
marche
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
['company.admin', 'profil']
c'est une forme qui n'est pas flexible au niveau JS, alors qu'un Object on peut facilement le merge, rajouter des keys, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
|
||
Well, please | ||
- Open an Issue describing your feature/bug/whatever addition you want to make, | ||
- If you feel 💪 enough, open a PR with some commits and reference your issue number inside. If you're also using ZenHub (💕) you can attach your PR to your issue ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing api documentation to explain how to use methods like sideload
, filter
, sort
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
La doc est au niveau de la def des méthodes cf src/builders/JsonapiResourceReader.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sinon cf #4
README.md
Outdated
method: 'GET', | ||
path: '/employee/profile/:id', | ||
params: { id: employeeId } | ||
collection: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We finally use collection, not a ReadListResource ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oups, ça traine
README.md
Outdated
|
||
requestBuilder = new JsonapiRequestBuilder({ | ||
resource: employeeReader, | ||
method: 'GET', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to specify method param ? Why not just use instanceof
check on resource to determine which method to use ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seem to be coded btw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep wrote this a month ago, needs cleanup
src/JsonApiConnector.js
Outdated
} | ||
} | ||
|
||
export const getMainConnector = JsonApiConnector.connector; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To delete ? Replaced by Api ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aaaah merde j'avais zappé ce truc là on avait parlé de connecteur a un moment mais je sais plus ce qu'on voulait y mettre dedans...
src/utils/builders.js
Outdated
return flatten(currentSideloads); | ||
}; | ||
|
||
/* Resolve path dulications of filters, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad comment missing one * and one new line
src/utils/builders.js
Outdated
return currentFilters; | ||
}; | ||
|
||
/* Assemble sorting paths, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad comment missing one * and one new line
src/utils/builders.js
Outdated
throw new Error(`Sorting only accepts nested objects with ending values being strings 'asc' or 'desc', but received ${currentSortValueOrObject}`); | ||
}); | ||
|
||
/* @private |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad comment missing one * and one new line
src/utils/builders.js
Outdated
return { url: mappedRoute, replacedParams }; | ||
}; | ||
|
||
/* @private |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad comment missing one * and one new line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+ missing params comments
src/utils/builders.js
Outdated
} | ||
}; | ||
|
||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad comment missing one * + missing param comment
DELETE via #5 |
26ce70c
to
8d9e9b3
Compare
src/api.js
Outdated
/** | ||
* @return {String} | ||
*/ | ||
get name() { return this._url; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name
return the _url
? o.O
src/api.js
Outdated
* @param {String} | ||
*/ | ||
set url(url) { this._url = url; } | ||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing carriage return
* @param {Object} params | ||
* @param {JsonapiResourceBuilder} params.resource | ||
* @param {String} params.httpMethod | ||
* @param {String} params.path Path of the request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
endpoint
instead of path
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oui parce que justement path c'est le path sans le host alors que l'endpoint ce serait le host quoi. L'endpoint provient de l'API, le path étant le "chemin relatif" de la requête
* @param {Object} params.meta Additional meta to add to the json:api payload | ||
*/ | ||
constructor({ | ||
resource = null, httpMethod = null, path = '', params = {}, api = null, meta = {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put all arguments on new line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ugh ça fait bizarre...
|
||
/** | ||
* Merge additional request metas | ||
* @param {Object} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing param name
|
||
/** | ||
* Indicates the resource can reuse existing cache if newer that +date+ | ||
* @param {Date} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One useless space between @param and {Date} + missing param name
* # => will remember sorting | ||
* - FIRST on company.name (asc assumed to mean Alphabetically) | ||
* - SECOND on rating (desc assumed to mean best-rated first) | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
* @return {Object[]} | ||
*/ | ||
mapOfJoinedFilters() { | ||
const mapOfFiltersAsPair = splatFilters('', this.filters).map(([key, values]) => ({ [key]: values.map(v => encodeURIComponent(v)).join(',') })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split this line to more readable 🙏
src/utils/builders.js
Outdated
@@ -0,0 +1,206 @@ | |||
import { | |||
flatten, | |||
isObject, isArray, isString, isBoolean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put all items on new line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Y'avais une séparation logique des imports pourtant...
No description provided.