Formerly calions-app/remote-resource. Search finds this package by either name.
Rerouted (retagged, needs approval). The tag now points at a different commit than when this version was published. The Lamdera package server serves a copy recovered from https://github.com/FabienHenon/remote-resource.
What we checked: Tag 1.0.0 is still on github.com/FabienHenon/remote-resource; its commit 0fc95f001af0 is from 2021-05-24 16:05 UTC, after the version was published (2019-09-06 10:19 UTC); elm.json differs from package.elm-lang.org's; the exposed modules match docs.json; the zip's SHA-1 is not the published one and nothing else confirms its contents.
We could not verify this copy against what was published, so the Lamdera compiler asks before using it (y/n). Without a terminal, as in CI, it stops with an error unless approved:
lamdera make --auto-approve-package-rerouting approves rerouted versions for that run,LAMDERA_AUTO_APPROVE_PACKAGE_REROUTING=1 does the same for every run in that environment,LAMDERA_CACHE=off skips the Lamdera package server altogether: packages come from package.elm-lang.org and GitHub only, as with elm, and a rerouted version then fails to download.Details · package.elm-lang.org's zip: https://github.com/FabienHenon/remote-resource/zipball/1.0.0/
Remote Resource alllows you to handle foreground and background resources, using https://package.elm-lang.org/packages/krisajenkins/remotedata/latest/.
For instance, let's say you want to retrieve a list of posts. You are using the RemoteData package, thus you can handle the state of your request (Loading, Success, etc...). You will probably display a loading icon while your request is in progress, and once it has been fully retrieved you will display your posts. But now, let's say you know your posts have changed and you would like to update them. You will probably want to send another request to your webservice with the same Elm RemoteData you used when you first retrieved your posts. That means your users will see your posts disapear for a few milliseconds (depending on the latency and network speed), replaced by a loading icon, to be finally updated and displayed again to your users.
Now, with RemoteResource you can refresh your posts in the background. Than means that you keep displaying your "old" posts to your users,
and when the new data has been retrieved you can replace your old posts by the new ones without your users seeing some loading icon!
Definition of the RemoteResource.
error is the error type, usually a Http.Errorres is your final resource, the one you are trying to retrieveInitializes the remote resource. This is the first thing to do to get a brand new RemoteResource.
To mark you foreground resource as Loading.
Your background resource will be reset to NotAsked.
RemoteResource.init |> RemoteResource.loadingTo mark your background resource as Loading
This does not change your foreground resource.
RefreshPosts ->
( posts |> RemoteResource.reloading, Cmd.none )Set the foreground resource. This will reset the background resource to NotAsked.
Set the foreground resource without resetting the background resource.
If the foreground resource is in Loading state, this function will update the foreground resource.
Otherwise, this will update the background resource without changing the foreground resource.
That means that you can use this function both when this is the first time you retrieve your resources (in this case you want to set the foreground resource), and when you want to refresh your resources and you already have foreground resources (in this case, maybe you want to store your background resources and tell your users there are new resources awailable before replacing the foreground resources))
Directly update the background resource without changing the foreground resource
If the current background resource is in Success state, then we replace the foreground resource by the background resource and
we set the background resource to NotAsked
Get the current foreground resource
Get the current background resource
Get a tuple with the foreground resource and the background resource.
You will retrieve the final resource, thus, if the resource is not in Success state, the default resource will be returned.
Map your foreground resource (RemoteData.map is applied to the foreground resource)
Map your background resource (RemoteData.map is applied to the background resource)
Compare the foreground and the background resources to check if there are different (In this case you could tell your users new resources have arrived).
Success state this will return false.Success state but foreground resource is not in Success state this will return trueSuccess state the compare function you provide will be used to determine if the resources are different
This is just an alias for
RemoteData error res