-
Notifications
You must be signed in to change notification settings - Fork 251
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
clean up usage of null/undefined #377
Conversation
Instead, change `putCookie` invocation depending on whether `callback` is provided.
`promiseCallback.resolve()` is implemented as `cb(); return promise`, so doing `promiseCallback.callback(); return promiseCallback.promise` is unnecessary.
Primarily allowing either value for user input.
secure: boolean | undefined | ||
httpOnly: boolean | undefined | ||
extensions: string[] | null | undefined | ||
key: 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.
All of these props seem to have | undefined
, but not actually need it, because none of the cookieDefaults
are undefined
.
creationIndex: number | ||
hostOnly: boolean | null | ||
pathIsDefault: boolean | null | ||
lastAccessed: Date | 'Infinity' | null | ||
sameSite: string | 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.
sameSite
does actually use undefined
to mean "no value". Which is anomalous, but more of a change than I'd want to deal with, here.
this.key = options.key ?? cookieDefaults.key | ||
this.value = options.value ?? cookieDefaults.value | ||
this.expires = options.expires ?? cookieDefaults.expires | ||
this.maxAge = options.maxAge ?? cookieDefaults.maxAge | ||
this.domain = options.domain ?? cookieDefaults.domain | ||
this.path = options.path ?? cookieDefaults.path | ||
this.secure = options.secure ?? cookieDefaults.secure | ||
this.httpOnly = options.httpOnly ?? cookieDefaults.httpOnly | ||
this.extensions = options.extensions ?? cookieDefaults.extensions | ||
this.creation = options.creation ?? cookieDefaults.creation | ||
this.hostOnly = options.hostOnly ?? cookieDefaults.hostOnly | ||
this.pathIsDefault = options.pathIsDefault ?? cookieDefaults.pathIsDefault | ||
this.lastAccessed = options.lastAccessed ?? cookieDefaults.lastAccessed | ||
this.sameSite = options.sameSite ?? cookieDefaults.sameSite |
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.
TypeScript complains if we use Object.assign
, so I just made it all explicit.
@wjhsf I'm finding this PR a bit too hard to review. Now that we've done most of the major cleanup with the migration to TypeScript I think this would be easier to review as separate, smaller PRs for each of the included changes such as:
|
This standardizes most of our methods to accept both null and undefined, and mostly return a value or undefined. Exceptions that I noticed are
canonicalDomain
,getPublicSuffix
,permuteDomain
, anddomainMatch
, which all return null. I don't remember why I skipped them when I originally did this, so I figured I'd just leave them for now. (I did most of this work a while ago, and evidently never pushed!)This also introduces a helper type
Nullable<T>
for readability.