Skip to content
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

Merged
merged 26 commits into from
Oct 10, 2018
Merged

Feature/resource builder #2

merged 26 commits into from
Oct 10, 2018

Conversation

Startouf
Copy link
Member

No description provided.

@Startouf Startouf added the enhancement New feature or request label May 31, 2018
@Startouf Startouf self-assigned this May 31, 2018
@Startouf Startouf requested a review from DOMEYD May 31, 2018 19:35
@Startouf Startouf force-pushed the feature/resource-builder branch from b77ae10 to 1e57d17 Compare May 31, 2018 23:40
Copy link
Contributor

@DOMEYD DOMEYD left a 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
Copy link
Contributor

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

Copy link
Member Author

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

@DOMEYD
Copy link
Contributor

DOMEYD commented Jun 9, 2018

Pour les method private elle doivent être préfixé par un underscore _methodName

Copy link
Contributor

@DOMEYD DOMEYD left a 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 */
Copy link
Contributor

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

Copy link
Member Author

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...

Copy link
Member Author

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);
};
};
Copy link
Contributor

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 ?

Copy link
Member Author

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,
);
Copy link
Contributor

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
);
}
Copy link
Contributor

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(
Copy link
Contributor

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

DOMEYD
DOMEYD previously requested changes Jun 9, 2018

/* @api private */
get requestActionTypePrefix() {
return 'READ';
Copy link
Contributor

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 :(

Copy link
Member Author

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

Copy link
Member Author

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

@Startouf Startouf changed the title [WIP] Feature/resource builder Feature/resource builder Aug 4, 2018
@Startouf Startouf changed the title Feature/resource builder [WIP] Feature/resource builder Aug 4, 2018
@Startouf Startouf force-pushed the feature/resource-builder branch from 06131ab to 096bc51 Compare August 4, 2018 16:32
@Startouf Startouf changed the title [WIP] Feature/resource builder Feature/resource builder Aug 4, 2018
@Startouf Startouf dismissed DOMEYD’s stale review August 4, 2018 16:33

Implemented review and added missing code related to URL generation

@Startouf Startouf force-pushed the feature/resource-builder branch from d42211f to 00c099e Compare August 4, 2018 16:53
DOMEYD
DOMEYD previously requested changes Aug 7, 2018
Copy link
Contributor

@DOMEYD DOMEYD left a 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 } })
Copy link
Contributor

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

Copy link
Member Author

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

Copy link
Member Author

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.

Copy link
Contributor

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 !
Copy link
Contributor

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

Copy link
Member Author

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

Copy link
Member Author

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,
Copy link
Contributor

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 ?

Copy link
Member Author

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',
Copy link
Contributor

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 ?

Copy link
Contributor

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

Copy link
Member Author

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

}
}

export const getMainConnector = JsonApiConnector.connector;
Copy link
Contributor

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 ?

Copy link
Member Author

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...

return flatten(currentSideloads);
};

/* Resolve path dulications of filters,
Copy link
Contributor

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

return currentFilters;
};

/* Assemble sorting paths,
Copy link
Contributor

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

throw new Error(`Sorting only accepts nested objects with ending values being strings 'asc' or 'desc', but received ${currentSortValueOrObject}`);
});

/* @private
Copy link
Contributor

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

return { url: mappedRoute, replacedParams };
};

/* @private
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 + missing params comments

}
};

/*
Copy link
Contributor

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

@Startouf
Copy link
Member Author

Startouf commented Aug 7, 2018

DELETE via #5

DOMEYD
DOMEYD previously requested changes Aug 15, 2018
src/api.js Outdated
/**
* @return {String}
*/
get name() { return this._url; }
Copy link
Contributor

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; }
/**
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

endpoint instead of path ?

Copy link
Member Author

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 = {},
Copy link
Contributor

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

Copy link
Member Author

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}
Copy link
Contributor

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}
Copy link
Contributor

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)
*/
Copy link
Contributor

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(',') }));
Copy link
Contributor

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 🙏

@@ -0,0 +1,206 @@
import {
flatten,
isObject, isArray, isString, isBoolean,
Copy link
Contributor

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

Copy link
Member Author

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...

@Startouf Startouf merged commit df8c407 into master Oct 10, 2018
@Startouf Startouf deleted the feature/resource-builder branch October 10, 2018 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants