Skip to content

Commit

Permalink
🐛 fix error "Maximum call stack size exceeded"
Browse files Browse the repository at this point in the history
Use a Tail Recursion implementation.

Implementation slows down the process because every update of the model
generates the link (which is somehow time consuming). I'm looking for
a better approach to manage downloads with elm.
  • Loading branch information
ccamel committed Aug 26, 2017
1 parent fe8d694 commit 7909531
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/elm/Page/Maze.elm
Original file line number Diff line number Diff line change
Expand Up @@ -658,28 +658,27 @@ asJsonValue : Maze -> Value
asJsonValue maze =
let
cellsToValue x y acc =
if x >= maze.width
then cellsToValue 0 (y + 1) acc
else if y >= maze.height
if x < 0
then cellsToValue (maze.width - 1) (y - 1) acc
else if y < 0
then acc
else
-- dense representation of the cells
(object [
("x", int x)
,("y", int y)
,("sides", maze
|> cellAt x y
|> withDefault []
|> map (nameSide >> string)
|> list)
])
::
(cellsToValue (x + 1) y acc)
-- dense representation of the cells
cellsToValue (x - 1) y
((object [
("x", int x)
,("y", int y)
,("sides", maze
|> cellAt x y
|> withDefault []
|> map (nameSide >> string)
|> list)
]) :: acc)
in
object [
("width", int maze.width)
,("height", int maze.height)
,("cells", list <| cellsToValue 0 0 [])
,("cells", list <| cellsToValue (maze.width - 1) (maze.height - 1) [])
,("state", string <| stateString maze)
]

Expand Down

0 comments on commit 7909531

Please sign in to comment.