Created
November 16, 2019 13:37
-
-
Save maxfarseer/87b3fd4878fdb9002e48c9ae4ad32f95 to your computer and use it in GitHub Desktop.
Making impossible state video
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Question модуль | |
module Question exposing ( History(..) ) | |
type History = | |
History | |
{ previous : List Question | |
, current : Question | |
, remaining : List Question | |
} | |
-- внутри модуля History мы можем работать с history | |
-- как нам вздумается | |
-- например доставать значения из History | |
-- через привычную ".", | |
-- (History { previous, ...} as history ) | |
-- history.current | |
-- Затем вместо exposing History(..) | |
-- что означает, "выставь наружу" тип History и конструктор типа | |
-- мы оставляем только | |
-- module Question exposing ( History ) | |
-- теперь в других файлах, можно использовать этот тип | |
-- но нельзя достутчаться вовнутрь, как быть? | |
-- Ответ: из модуля Question, показать наружу хелпер-функции | |
questions : History -> List Questions | |
currentQuestion: History -> Question | |
-- ... | |
-- Для чего? | |
-- чтобы скрыть внутреннюю реализацию. В будущем, | |
-- если мы захотим изменить что-то внутри, | |
-- и будем придерживаться такого же API "наружу", | |
-- то нам не придется ничего менять в других модулях! | |
-- No breaking changes, как говорится. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment