{"id":23613702,"url":"https://github.com/freckle/resource-status-js","last_synced_at":"2025-11-06T09:30:33.832Z","repository":{"id":136508826,"uuid":"612362184","full_name":"freckle/resource-status-js","owner":"freckle","description":null,"archived":false,"fork":false,"pushed_at":"2023-05-03T22:58:25.000Z","size":1003,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-13T21:57:06.071Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/freckle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-10T19:21:14.000Z","updated_at":"2024-07-09T04:05:31.135Z","dependencies_parsed_at":null,"dependency_job_id":"5ac9105e-ce5f-41a0-ba19-94f1f9c08305","html_url":"https://github.com/freckle/resource-status-js","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":"freckle/npm-package-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freckle%2Fresource-status-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freckle%2Fresource-status-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freckle%2Fresource-status-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freckle%2Fresource-status-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/freckle","download_url":"https://codeload.github.com/freckle/resource-status-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239491352,"owners_count":19647811,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-27T17:18:49.992Z","updated_at":"2025-02-18T14:45:32.692Z","avatar_url":"https://github.com/freckle.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Resource Status\n\nDefines the `ResourceStatusT` type and utilities operating on this type.\n\n## Install\n\n```sh\nyarn add @freckle/resource-status\n```\n\n## Versioning and release process\n\nSee [RELEASE.md](./RELEASE.md).\n\n## `ResourceStatusT\u003cR\u003e`\n\nWraps data from a resource `R` with metadata to describe the status of accessing\nand updating the data. The `status` field can be used to react accordingly:\n\n```ts\ntype Props = {resource: ResourceStatusT\u003c{username: string}\u003e}\nconst UserView = ({resource}: Props) =\u003e {\n  switch (resource.status) {\n    case 'idle':\n      return \u003cp\u003eUser has not been loaded\u003c/p\u003e\n    case 'loading':\n      return \u003cp\u003eLoading user\u003c/p\u003e\n    case 'reloading':\n      return \u003cp\u003eUser: {resource.data.username} (reloading)\u003c/p\u003e\n    case 'error':\n      return (\n        \u003cp\u003e\n          Error loading user: \u003cpre\u003e{JSON.stringify(resource.error)}\u003c/pre\u003e\n        \u003c/p\u003e\n      )\n    case 'complete':\n      return \u003cp\u003eUser: {resource.data.username}\u003c/p\u003e\n    case 'updating':\n      return \u003cp\u003eUser: {resource.data.username} (pending update)\u003c/p\u003e\n    case 'updating-error':\n      return (\n        \u003cp\u003e\n          Error updating user {resource.data.username}: \u003cpre\u003e{JSON.stringify(resource.error)}\u003c/pre\u003e\n        \u003c/p\u003e\n      )\n    default:\n      return exhaustive(resource)\n  }\n}\n```\n\n## Utilities\n\nUtilities are defined to make operating on a resource status.\n\n### `maybeResourceData(resource)`\n\nReturns the underlying `resource.data` if it exists.\n\n### `fromMaybeResourceData(resource, default)`\n\nReturns the underlying `resource.data` if it exists, or `default` otherwise.\n\n### `isFetching(resource)`\n\nReturns `true` when a `resource` is loading or reloading.\n\n### `updateResource(resource, updateFn)`\n\nPerforms `updateFn(resource.data)` if there exists data in the resource, and\nreturns a new `resource`. This is convenient for reducer-style updates:\n\n```ts\ntype State = ResourceStatusT\u003c{username: string; token: string}\u003e\ntype Action =\n  | {type: 'USER_UPDATE_REQUEST'}\n  | {type: 'USER_UPDATE_RESPONSE'; data: {username: string}}\n\nconst reducer = (state: State, action: Action) =\u003e {\n  switch (action.type) {\n    case 'USER_UPDATE_REQUEST':\n    // ...\n    case 'USER_UPDATE_RESPONSE':\n      return updateResource(state, user =\u003e ({\n        ...user,\n        username: action.data.username\n      }))\n  }\n}\n```\n\n---\n\n[LICENSE](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreckle%2Fresource-status-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreckle%2Fresource-status-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreckle%2Fresource-status-js/lists"}