{"id":16710896,"url":"https://github.com/thomasweiser/elmfire-extra","last_synced_at":"2025-04-10T05:35:40.078Z","repository":{"id":57674724,"uuid":"44519340","full_name":"ThomasWeiser/elmfire-extra","owner":"ThomasWeiser","description":"High-level API for ElmFire","archived":false,"fork":false,"pushed_at":"2016-04-01T11:21:27.000Z","size":28,"stargazers_count":17,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-10T00:30:31.739Z","etag":null,"topics":["elm","elmfire","firebase"],"latest_commit_sha":null,"homepage":" http://package.elm-lang.org/packages/ThomasWeiser/elmfire-extra/latest","language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ThomasWeiser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-19T07:55:01.000Z","updated_at":"2022-05-27T14:32:26.000Z","dependencies_parsed_at":"2022-09-02T14:23:08.061Z","dependency_job_id":null,"html_url":"https://github.com/ThomasWeiser/elmfire-extra","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThomasWeiser%2Felmfire-extra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThomasWeiser%2Felmfire-extra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThomasWeiser%2Felmfire-extra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThomasWeiser%2Felmfire-extra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ThomasWeiser","download_url":"https://codeload.github.com/ThomasWeiser/elmfire-extra/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248164022,"owners_count":21058066,"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":["elm","elmfire","firebase"],"created_at":"2024-10-12T20:09:59.317Z","updated_at":"2025-04-10T05:35:40.053Z","avatar_url":"https://github.com/ThomasWeiser.png","language":"Elm","funding_links":[],"categories":[],"sub_categories":[],"readme":"# High-level API for ElmFire\n\n## Treat your Firebase data like a local Dict\n\nThis package provides an API layer on top of the basic [ElmFire](http://package.elm-lang.org/packages/ThomasWeiser/elmfire/latest) API,\nthat treats a Firebase collection as a key-value store and\nmakes it available basically as an Elm dictionary with corresponding operations on it.\n\nThe package consists of two modules, for reading and writing respectively:\n\n- `ElmFire.Dict`\n  - Mirroring a Firebase location as an Elm `Dict`\n  - Getting a signal of all updates\n  - One-time retrieval\n\n\n- `ElmFire.Op`\n  - Inserting, updating and deleting of single key-value pairs\n  - Inserting and deleting lists of key-value pairs\n  - Updating the whole collection via the higher-order functions `map`, `filter` and `filterMap`\n  - Operations on the whole store can selectively be run sequentially, in parallel or as a single transaction.\n\n## General Usage Pattern\n\nThese two modules are intended to be used together.\n\n- The state of the mirrored store will be held as a dictionary as part of the application's model.\n- Operations on the store are performed by the appropriate actions of the application.\n\nLocal modifications will be reflected immediately in addition to be sent to the Firebase server and to other clients subscribed to the same Firebase location.\nLikewise, remote modifications will be reflected in the local mirror.\n\n## Configuration\n\nAll functionality of the package is guided by a configuration record that defines type mappings and other specifics of the Firebase collection.\n\n```elm\ntype alias Config v =\n  { location: ElmFire.Location\n  , orderOptions: ElmFire.OrderOptions\n  , encoder: v -\u003e JD.Value\n  , decoder: JD.Decoder v\n  }\n\n```\n\n`location` specifies the Firebase and sub-path where the store is hosted.\n\n`orderOptions` can be used to filter and limit the elements, that should be included in the local mirror. Use `ElmFire.noOrder` to access the whole collection.\n\nThe API is parameterized on the store's value type `v`. This can be any Elm type, as long as suitable conversion functions are provided.\nNote that the keys are always of type String.\n\n`encoder` and `decoder` are the functions used to convert between the value type in Elm code and the JSON schema in the Firebase.\n\n## Example Code\n\nWe setup a simple store with values of type `Int`.\n```elm\nurl = \"https://myfirebase.firebaseio.com/sub/path\"\n\nconfig : ElmFire.Dict.Config Int\nconfig =\n  { location = ElmFire.fromUrl url\n  , orderOptions = ElmFire.noOrder\n  , encoder = Json.Encode.int\n  , decoder = Json.Decode.int\n  }\n```\nStart to mirror the store as a signal `model`.\n```elm\nmirror = ElmFire.Dict.mirror config\n\nport initSubscription : Task ElmFire.Error (Task ElmFire.Error ())\nport initSubscription = fst mirror\n\nmodel : Signal (Dict String Int)\nmodel = snd mirror\n```\nDefine two operations on the store and run them. The result will be reflected in the mirror.\n```elm\n-- Initialize the store  (run the tasks via a port)\nopInit : ElmFire.Op.Operation Int\nopInit =\n  ElmFire.Op.fromList\n    ElmFire.Op.sequential\n    [(\"foo\",1), (\"bar\",2)]\n\n-- Double each value\nopMap : ElmFire.Op.Operation Int\nopMap =\n  ElmFire.Op.map\n    ElmFire.Op.sequential\n    (\\key val -\u003e val * 2)\n\nport runOperation : Task ElmFire.Error (List ElmFire.Reference)\nport runOperation =\n  Task.sequence \u003c|\n    List.map (ElmFire.Op.operate config) [opInit, opMap, opMap]\n```\nThe package includes the complete example code in directory `example/`. There is also a more detailed demonstration app in directory `demo/`\n\n## Examples of projects using elmfire-extra\n\n### TodoMVC\n\nAn example usage of this package is [this fork of TodoMVC](https://github.com/ThomasWeiser/todomvc-elmfire). It uses Firebase to store and share the todo items.\n\nIt utilizes `ElmFire.Dict` and `ElmFire.Op` in the aforementioned [usage pattern](#general-usage-pattern).\n\n### elmfire-extra-hello-world\n\nRaine Revere published some instructive minimal example code. Starts [here](https://github.com/metaraine/elmfire-extra-hello-world).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomasweiser%2Felmfire-extra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthomasweiser%2Felmfire-extra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomasweiser%2Felmfire-extra/lists"}