Elm in Action / Elm в действии Год издания: 2020 Автор: Feldman R. / Фельдман Р. Издательство: Manning ISBN: 9781617294044 Язык: Английский Формат: PDF Качество: Издательский макет или текст (eBook) Интерактивное оглавление: Да Количество страниц: 344 Описание: Elm in Action teaches you the Elm language along with a new approach to coding frontend applications. Chapter by chapter, you’ll create a full-featured photo-browsing app, learning as you go about Elm’s modular architecture, Elm testing, and how to work seamlessly with your favorite javascript libraries. You’ll especially appreciate author and Elm core team member Richard Feldman’s unique insights, based on his thousands of hours writing production code in Elm. When you’re done, you’ll have a toolbox of new development skills and a stunning web app for your portfolio. What's inside: Scalable design for production web applications Single-page applications in Elm Data modeling in Elm Accessing javascript from Elm
Примеры страниц
Оглавление
preface xi acknowledgments xiii about this book xv about the author xix about the cover illustration xx PART 1 GETTING STARTED ............................................... 1 1 Welcome to Elm 3 1.1 How Elm fits in 5 1.2 Expressions 7 Using elm repl 7 ■ Building expressions 8 ■ Booleans and conditionals 11 1.3 Functions 13 Defining functions 14 ■ Importing functions 15 ■ Creating scope with let-expressions 18 ■ Anonymous functions 19 Operators 20 1.4 Collections 22 Lists 23 ■ Records 24 ■ Tuples 26 2 Your first Elm application 29 2.1 Rendering a page 30 Describing a page using the Html module 31 ■ Building a project 37viii CONTENTS 2.2 Handling user input with The Elm Architecture 40 Representing application state with a model 40 ■ Handling events with messages and updates 48 3 Compiler as assistant 55 3.1 Documenting guarantees with type annotations 56 Adding optional type annotations 56 ■ Annotating functions with type variables 58 ■ Reusing annotations with type aliases 61 ■ Annotating longer functions 62 3.2 Using case-expressions and custom types 65 Using case-expressions 65 ■ Enumerating possibilities with custom types 67 ■ Holding data in custom types 71 ■ Representing flexible messages with custom types 74 3.3 Generating random numbers with commands 77 Describing random values with Random.Generator 77 Introducing commands to The Elm Architecture 78 ■ Generating random values with Random.generate 80 PART 2 PRODUCTION-GRADE ELM .................................. 89 4 Talking to servers 91 4.1 Preparing for server-loaded data 92 Modeling incremental initialization 92 ■ Resolving data dependencies 95 4.2 Fetching data from a server 100 Describing HTTP requests 100 ■ Sending HTTP requests 104 4.3 Decoding JSON 111 Decoding JSON strings into results 111 ■ Decoding JSON collections 112 ■ Decoding JSON HTTP responses 117 5 Talking to JavaScript 125 5.1 Using custom elements 126 Importing custom elements 127 ■ Handling custom events 133 Responding to slider changes 137 5.2 Sending data to JavaScript 141 Creating a command by using a port 141 ■ Receiving data from Elm 146 ■ Timing DOM updates 150CONTENTS ix 5.3 Receiving data from JavaScript 152 Receiving real-time data from JavaScript via ports 152 ■ Receiving initialization arguments via flags 156 6 Testing 167 6.1 Writing unit tests 168 Introducing tests 168 ■ Unit testing a JSON decoder 172 Narrowing test scope 176 6.2 Writing fuzz tests 180 Converting unit tests to fuzz tests 180 ■ Testing update functions 184 ■ Creating multiple tests with one function 186 6.3 Testing views 188 Testing DOM structure 189 ■ Fuzzing view tests 193 Testing user interactions 196 PART 3 BUILDING BIGGER ............................................ 203 7 Data modeling 205 7.1 Storing values by keys in dictionaries 206 Setting up the page 207 ■ Storing photos by URL in a dictionary 209 7.2 Modeling trees by using recursive custom types 218 Defining trees by using custom types 218 ■ Recursive messages 223 ■ Event handlers with recursive messages 226 7.3 Decoding graphs and trees 228 Decoding dictionaries 228 ■ Decoding recursive JSON 231 Accumulating while decoding 235 8 Single-page applications 246 8.1 Framing the page 247 Creating Main.elm 247 ■ Rendering the header and footer 249 Skipping unnecessary renders with Html.Lazy 253 8.2 Routing 258 Handling the initial URL 258 ■ Parsing URL paths 263 Handing URL changes 267 8.3 Delegating pages 272 Revising module structure 272 ■ Initializing page states 275 Delegating page logic 279x CONTENTS appendix A Getting set up 291 appendix B Installing Elm packages 294 appendix C Html.Lazy’s change check 298 index 303
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum