elm-architecture | The Elm Architecture in JavaScript | Reactive Programming library
kandi X-RAY | elm-architecture Summary
kandi X-RAY | elm-architecture Summary
The Elm Architecture in JavaScript
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of elm-architecture
elm-architecture Key Features
elm-architecture Examples and Code Snippets
Community Discussions
Trending Discussions on elm-architecture
QUESTION
For example: in this repo, https://github.com/evancz/elm-architecture-tutorial/ , how do I load one of the Elm files into elm repl, so I can evaluate functions, look at type signatures, etc ?
In Haskell I would use :l
...ANSWER
Answered 2019-Jan-12 at 10:31Unfortunately the examples on the GitHub link don't expose anything, so you cannot import from them as-is. Since you have access to source code you can of course modify the sources to support this, so read on :)
In general, it is done in repl by using command import
import SomeModule exposing (fun1, fun2)
SomeModule
is the name of the module where to import, and fun1
and fun2
are functions to import. For importing all functions, use (..)
When the repl is started in the same folder as the modules, the import works. Maybe there's some option for repl to set the sources directory, but I could not find it.
But for something to be imported from a module, it needs to export it in the source file, like this for example
module SomeModule exposing (fun1, fun2)
QUESTION
Suppose I want to create a webpage with two components, say a Navbar
and a Body
. These two components do not interact with each other and can be developed independently. So, I have two elm files which have the following components in each of them:
ANSWER
Answered 2018-Jul-05 at 20:20I think @dwaynecrooks covered the technical aspects of the question. But I believe your problem implies a design aspect too.
As others pointed out: thinking in terms of components will almost certainly take you down a not so appealing path with Elm. (Many people start there. I and my team started there over 2 years ago, and it took us 3 apps/major redesigns to get to a point where I think we can be happy at least about the fundamentals.)
Instead of components, I suggest you should think of your Elm application as a tree. Each node of your tree represents a level of abstraction, and describes the behavior of your application on that level. When you have the feeling that there is too much detail for a given level, you can start thinking about how new, lower levels of abstraction could be introduced as child nodes.
In practice each node is implemented in its own Elm module: parents import their children. You may also consider that you don't have to stick to the usual model/update/view
signatures, rather you should focus on the particularities of your app's domain. This is what – in my read – Richard Feldman is doing in his Real World SPA example app. And Evan's Life of a file talk is related to this question too.
navbar
+ body
Regarding your particular case – it is not a rare case – here is my experience. If we say that our webapp has a navbar and then some body, this is a pretty static description of the app. This kind of description may fit a component based thinking, but it is less helpful if you want to end up with an elegant Elm app.
Instead, it is worth trying to describe the behavior of your app at this level of abstraction, which may sound something like this: The user can select x
,y
,z
items in a navbar. Clicking on those items will affect the item in q
way and also affect the body in either a
, or b
way. He can also click on v
in the navbar, which would show a popup or do w
, which logs him out of the app.
If you take this description and apply the logic that I described above, you should probably end up with some sort of a design where most of your navbar is described in your highest level of abstraction. This includes items x
, y
, z
, v
and behaviors a
, b
, w
. Now, behavior a
may mean that a specific, rich page must be displayed, which has its own detailed behavior that is described on a lower level of abstraction, whereas behavior b
may mean that based on the selection some content must be loaded, and again the details of this loading process is worked out on a lower level of abstraction. And so on.
When we started approaching the problem this way, it became much more straight forward to find out how to split up logic, and how to deal with special cases. We realized, for instance, that when someone said that a page wants to display some stuff "in the navbar", what she really meant was that the navbar should collapse (or transform) for a particular page so that page can display it's own header in that area.
Focusing on the app's behavior instead of static content areas helped with this.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install elm-architecture
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page