New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got Bibli.elm:1970 Uncaught TypeError: Cannot read property 'ctor' of undefined OR 'Internal Structure' #727

Closed
savardd opened this Issue Sep 23, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@savardd

savardd commented Sep 23, 2016

In elm 0.17.1

In the sample code uploaded there is two errors that we can see.
With the code as is, if we click on 'fetch', there will be an error on the javascript console:
--> Bibli.elm:1970 Uncaught TypeError: Cannot read property 'ctor' of undefined

If we comment the line number 47 : ", viewBooks model" in the function view model,
the model will show as "{ books = "", test = "[]" }" once we click on fetch.

And if we rename the 'model' variable on the FetchSuccess to another name (amodel) for exemple, all the code works.

@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Sep 23, 2016

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot commented Sep 23, 2016

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@savardd

This comment has been minimized.

Show comment
Hide comment
@savardd

savardd Sep 23, 2016

import Html exposing (div, button, text)
import Html.App exposing (beginnerProgram)
import Html.Events exposing (onClick)

main =
  beginnerProgram
    { model = getInit
    , view = view
    , update = update
    }


type alias Book =
    { title: String
    , isbn: String
    , date: String
    }

type alias Model =
    { books: List Book
    , test: String
    }

getBooks: Model -> String -> List Book
getBooks model html =
    [ Book "" "" "" ]

getInit =
    { books = []
    , test = ""
    }


viewBook book =
    div [] []

viewBooks model =
    div []
    (
        List.map viewBook model.books
    )

view model =
  div []
    [ div [] [ text (toString model) ]
    , button [ onClick (FetchSuccess "") ] [ text "fetch" ]
    --, viewBooks model   -- COMMENT THIS LINE TO SEE 'Internal Structure'
    ]


type Msg = FetchSuccess String

update: Msg -> Model -> Model
update msg model =
  case msg of
    FetchSuccess a ->
        let
            isbns = []
            books = getBooks model a
            model = {model|test=toString isbns  -- If model renamed 'amodel' all works ok
                          ,books=books
                     }
        in
            model                               -- If model renamed 'amodel' all works ok

savardd commented Sep 23, 2016

import Html exposing (div, button, text)
import Html.App exposing (beginnerProgram)
import Html.Events exposing (onClick)

main =
  beginnerProgram
    { model = getInit
    , view = view
    , update = update
    }


type alias Book =
    { title: String
    , isbn: String
    , date: String
    }

type alias Model =
    { books: List Book
    , test: String
    }

getBooks: Model -> String -> List Book
getBooks model html =
    [ Book "" "" "" ]

getInit =
    { books = []
    , test = ""
    }


viewBook book =
    div [] []

viewBooks model =
    div []
    (
        List.map viewBook model.books
    )

view model =
  div []
    [ div [] [ text (toString model) ]
    , button [ onClick (FetchSuccess "") ] [ text "fetch" ]
    --, viewBooks model   -- COMMENT THIS LINE TO SEE 'Internal Structure'
    ]


type Msg = FetchSuccess String

update: Msg -> Model -> Model
update msg model =
  case msg of
    FetchSuccess a ->
        let
            isbns = []
            books = getBooks model a
            model = {model|test=toString isbns  -- If model renamed 'amodel' all works ok
                          ,books=books
                     }
        in
            model                               -- If model renamed 'amodel' all works ok
@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Sep 23, 2016

Contributor

You have run into this: elm/compiler#873.

Contributor

jvoigtlaender commented Sep 23, 2016

You have run into this: elm/compiler#873.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment