mirror of
https://github.com/desktop/desktop
synced 2024-09-18 07:32:01 +00:00
Review feedback: add comments, rename things… ✨
Co-Authored-By: Markus Olsson <634063+niik@users.noreply.github.com>
This commit is contained in:
parent
8d211caaff
commit
f982fe550f
17
app/src/models/equality-hash.ts
Normal file
17
app/src/models/equality-hash.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
/**
|
||||
* Types which can safely be coerced to strings without losing information.
|
||||
* As an example `1234.toString()` doesn't lose any information whereas
|
||||
* `({ foo: bar }).toString()` does (`[Object object]`).
|
||||
*/
|
||||
type HashableType = number | string | boolean | undefined | null
|
||||
|
||||
/**
|
||||
* Creates a string representation of the provided arguments.
|
||||
*
|
||||
* This is a helper function used to create a string representation of
|
||||
* an object based on its properties for the purposes of simple equality
|
||||
* comparisons.
|
||||
*/
|
||||
export function createEqualityHash(...items: HashableType[]) {
|
||||
return items.join('+')
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import { createHash } from './hash'
|
||||
import { createEqualityHash } from './equality-hash'
|
||||
import { Owner } from './owner'
|
||||
|
||||
export type GitHubRepositoryPermission = 'read' | 'write' | 'admin' | null
|
||||
|
@ -30,7 +30,7 @@ export class GitHubRepository {
|
|||
public readonly permissions: GitHubRepositoryPermission = null,
|
||||
public readonly parent: GitHubRepository | null = null
|
||||
) {
|
||||
this.hash = createHash([
|
||||
this.hash = createEqualityHash(
|
||||
this.name,
|
||||
this.owner.login,
|
||||
this.dbID,
|
||||
|
@ -41,8 +41,8 @@ export class GitHubRepository {
|
|||
this.issuesEnabled,
|
||||
this.isArchived,
|
||||
this.permissions,
|
||||
this.parent?.hash,
|
||||
])
|
||||
this.parent?.hash
|
||||
)
|
||||
}
|
||||
|
||||
public get endpoint(): string {
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
type HashableType = number | string | boolean | undefined | null
|
||||
|
||||
export function createHash(items: HashableType[]) {
|
||||
return items.join('+')
|
||||
}
|
|
@ -7,7 +7,7 @@ import {
|
|||
ForkContributionTarget,
|
||||
} from './workflow-preferences'
|
||||
import { assertNever, fatalError } from '../lib/fatal-error'
|
||||
import { createHash } from './hash'
|
||||
import { createEqualityHash } from './equality-hash'
|
||||
|
||||
function getBaseName(path: string): string {
|
||||
const baseName = Path.basename(path)
|
||||
|
@ -62,14 +62,14 @@ export class Repository {
|
|||
this.mainWorkTree = { path }
|
||||
this.name = (gitHubRepository && gitHubRepository.name) || getBaseName(path)
|
||||
|
||||
this.hash = createHash([
|
||||
this.hash = createEqualityHash(
|
||||
path,
|
||||
this.id,
|
||||
gitHubRepository?.hash,
|
||||
this.missing,
|
||||
this.workflowPreferences.forkContributionTarget,
|
||||
this.isTutorialRepository,
|
||||
])
|
||||
this.isTutorialRepository
|
||||
)
|
||||
}
|
||||
|
||||
public get path(): string {
|
||||
|
|
Loading…
Reference in a new issue