-
Notifications
You must be signed in to change notification settings - Fork 30
Conversation
Can someone update the repo settings so it prevents merging without an approval? Also the travis CI stuff hasn't finished but the merge button is still active. |
We have tried that, that causes issues with our release scripts, because we push some additional commits directly to master when we do a release. Restricting it only to admins then prevents non-admins from publishing a release, which is undesirable. So we work on the honour system for those that have commit access.
There are some transitory states when the additional checks. Initially the merge button will appear active, but often the refresh a page, once the git hook to travis has been properly fired, will remove the check. Again, we work on the honour system for committers. Be responsible. |
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.
A couple of comments
src/Outlet.ts
Outdated
@@ -30,7 +30,7 @@ export type Outlet< | |||
|
|||
export function Outlet<W extends WidgetBaseInterface, F extends WidgetBaseInterface, E extends WidgetBaseInterface>( | |||
outletComponents: Component<W> | OutletComponents<W, F, E>, | |||
outlet: string, | |||
outlet: string | Array<String>, |
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 use []
for array types, string[]
- Also should avoid using String
and use string
instead (https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html).
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.
Done, thanks for explaining, I will read that page. Can we lint for this sort of thing?
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.
@umaar https://palantir.github.io/tslint/rules/ban-types/ so it appears yes... let's open an issue on https://github.com/dojo/dojo2-package-template where the master tslint.json
file resides. We likely need to do a wholesale review.
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.
src/Router.ts
Outdated
getOutlet(outletId: string | Array<String>): OutletContext | undefined { | ||
if (Array.isArray(outletId)) { | ||
const outletContextArray = arrayFrom(this._outletContextMap); | ||
const outlets = arrayFrom(outletId); |
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.
Why do you need to arrayFrom
here? We are already know it is an array as we are in the Array.isArray(outletId)
block.
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 good catch, left over code from when I was trying to convert the "needle" we are trying to find into an array, even if it was one already. Removed!
src/Router.ts
Outdated
const outletContextArray = arrayFrom(this._outletContextMap); | ||
const outlets = arrayFrom(outletId); | ||
|
||
const matchingOutlet = find(outletContextArray, ([key]) => { |
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.
Would be nicer if you destructured this:
const [, matchingOutlet ] = find(...);
Then just return matchingOutlet
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 yes tried that too! TypeScript was complaining about something like undefined not being an array type and I think it makes sense. The find function can return undefined, and we can't destructure undefined. Is that your understanding too?
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.
If you are convinced that find()
will not return undefined
because of other checks or validations, you can use the escape hatch of the non-null assertion operator (find(...)!
). Our general convention is to comment the code though why you believe you are safe using the operator.
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.
Oh cool thanks for explaining that! In this particular case, I'm not convinced that find()
will never return undefined
so I think we can leave it as it is, useful to know though!
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 really try and avoid using !
to force TS to ignore strictNullChecks
in src code.
Could || []
after the find if it helps make the code clearer by enabling the destructuring.
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.
src/Router.ts
Outdated
}); | ||
|
||
return matchingOutlet ? matchingOutlet[1] : undefined; | ||
} else { |
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.
Don't need the else block as we are returning from within the if block
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.
Done. Would be really good if we linted for this, something like https://eslint.org/docs/rules/no-else-return for TS?
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.
It doesn't appear that tslint has it as an out of the box rule (https://palantir.github.io/tslint/rules/). We haven't experimented with custom rules, but it maybe again worth opening an issue for tracking. We looked at ESLints support of TypeScript about 9 months ago, and haven't since. We know there has been work on settling on an AST syntax for TypeScript (preliminary work is already in Babel) but haven't had the time to see if ESLint has matured in that aspect. We really need something that takes the AST from the TypeScript compiler. Either way, it is likely a good idea for a separate issue to further discuss trying to move to ESLint. I can see the long term benefits TBH.
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.
src/Router.ts
Outdated
@@ -439,8 +439,19 @@ export class Router<C extends Context> extends Evented implements RouterInterfac | |||
return this._outletContextMap.has(outletId); | |||
} | |||
|
|||
getOutlet(outletId: string): OutletContext | undefined { | |||
return this._outletContextMap.get(outletId); | |||
getOutlet(outletId: string | Array<String>): OutletContext | undefined { |
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.
string[]
over Array<String>
here as well.
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.
Done!
Thanks @agubler please give another review! |
@umaar what happens if multiple outlets match? |
The |
I'm not sure, because then it's dependant on the order of the outlets specified... do you think we should return all matching? |
I'm not really sure to be honest! If we returned an array of all matching outlets, what would be the use/benefit of that? |
@umaar I'm trying to think... It's almost as though we want the "deepest" location but the params from all matching outlets - Then these would be available in the mapParams function for the consumer to use? If this is desirable, it would be good to have a test that includes params too (that could verify this behaviour). So this test, would return a location of Lines 555 to 567 in 23f7072
|
Me and @agubler just had a call about this (thanks Ant very helpful 💯) and I would agree with your idea! It makes sense. Let me do that ✅ |
@agubler could you double check this PR (also please check if it's treating the multiple outlets in the way you expect!) thank you |
src/Router.ts
Outdated
return this._outletContextMap.get(outletId); | ||
getOutlet(outletIds: string | string[]): OutletContext | undefined { | ||
if (Array.isArray(outletIds)) { | ||
const combinedParams = outletIds.reduce((params, cur, index) => { |
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.
This section feels quite complicated now, do you think it could be simplified slightly? We could maybe use the path to determine if a matching outlet is deeper than an existing match and not need to loop through the context map.
Rough example:
let matchingOutlet: OutletContext | undefined = undefined;
let matchingParams: Parameters = {};
let matchingLocation = '';
for (let i = 0; i < outletIds.length; i++) {
const outletContext = this._outletContextMap.get(outletIds[i]);
if (outletContext) {
const { params, location } = outletContext;
matchingParams = { ...matchingParams, ...params };
if (!matchingOutlet || matchingLocation.indexOf(location) === -1) {
matchingLocation = location;
matchingOutlet = {
...outletContext,
params: matchingParams
};
}
}
}
return matchingOutlet;
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.
Thank you! I've just added a const outletIds = Array.isArray(outletId) ? outletId : [outletId];
to make sure we're dealing with an array, but apart from that, I'm using your example 👍
src/Router.ts
Outdated
getOutlet(outletId: string): OutletContext | undefined { | ||
return this._outletContextMap.get(outletId); | ||
getOutlet(outletId: string | string[]): OutletContext | undefined { | ||
const outletIds = Array.isArray(outletId) ? outletId : [outletId]; |
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.
nit: code style, should have spaces [ outletId ]
@umaar could do with updating the README also? |
81d787d
to
4a35fd0
Compare
@agubler readme updated |
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.
👍
Type: feature
The following has been addressed in the PR:
Description:
Enhance
getOutlet
so it can receive a single outlet ID or an array of outlet IDs.Resolves #103