-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Split into multiple files #57
Conversation
Thank you so much! I'd love to merge this. I'm not really willing to change the source code as much as this PR though. I don't have any issues with separating everything in files, but I rather like how this source code works and looks currently: export function isNegativeNumber(payload: any): payload is number {
return isNumber(payload) && payload < 0
}
export function isBoolean(payload: any): payload is boolean {
return getType(payload) === 'Boolean'
}
export function isRegExp(payload: any): payload is RegExp {
return getType(payload) === 'RegExp'
}
export function isMap(payload: any): payload is Map<any, any> {
return getType(payload) === 'Map'
}
export function isWeakMap(payload: any): payload is WeakMap<any, any> {
return getType(payload) === 'WeakMap'
}
// etc. And this PR is kind of a big change... It would feel to me like the source code is not mine anymore and in many places I have harder time reading it. So I'd like to request to retain the source code as-is for this PR, you can move Another thing I'd love to request to change is to not use default exports. I do not use default exports in any of my code anywhere as kind of a personal rule of thumb. There were in the past many cjs/esm issues with default exports that all went away not using it. So I'd like to request to only use named exports for this PR. PS: Not sure if you saw my email, but I'm available to chat on Discord if you want. |
Problem with this is that it discourages documentation like examples. For instance, that isBoolean(). Does it work ONLY on
👍
I think default exports are great! They make is so easy to import one thing from a package and really natively signify that something is the main export of a file. This works great when On the CJS note: I think that CJS is in decline. This ties into my question about whether or not you want to #47 which would solve the #37. More discussion on the pros and cons of default exports vs named exports has been discussed to death in airbnb/javascript#1365 where Airbnb explains why they use default exports |
@jcbhmr I think you misunderstood something. I mentioned I have no issues splitting it up into multiple files and agree that adding more JSDocs to each file is a great idea. I meant that I want to keep the source-code of the function bodies the same for now. If the PR can just split up the files, but keep the source-code as is, it'll be way easier to merge that first, then continue discussion source-code changes in individual PRs per function. What I mean is, no need to change // this:
export function isBoolean(payload: any): payload is boolean {
return getType(payload) === 'Boolean'
}
// to this:
export default function isBoolean(x: unknown): x is boolean {
return typeof x === "boolean";
} or // this
export function isRegExp(payload: any): payload is RegExp {
return getType(payload) === 'RegExp'
}
// to this
export default function isRegExp(x: unknown): x is RegExp {
try {
Object.getOwnPropertyDescriptor(RegExp.prototype, "source")!.get!.call(
x as RegExp
);
} catch {
return false;
}
return true;
} So if eg. you make a file called import { getType } from './utils.ts'
/** any JSDoc... feel free to add improvements here */
export function isBoolean(payload: any): payload is boolean {
return getType(payload) === 'Boolean'
} This is what I meant. Otherwise if you do everything at once, there's no easy way for me to discuss changes and clearly see what changed where. 😅 |
This can be further discussed in #55
it's a bit much to parse through. I am not seeing where exactly AirBnB's reasoning is in this thread. But a quick glance and this caught my eye:
This is kinda where I'm at. This and also all of the issues I've had in the past. Literally 10+ hours wasted in tooling hell and it all went away by using named exports. |
Yep! I misunderstood. Thanks for clearing that up for me! 😊👍 |
fixes #69
This PR would...