Od zera do JavaScript developera #6

Dawid Poslinski

https://miksturait.slack.com/

http://bit.ly/miksturait

Agenda

  1. Values, Types, and Operators
  2. Functions &Data Structures - Objects and Arrays
  3. Higher-order Functions
  4. Objects &  first project
  5. Classes and OOP practises
  6. Modules & Asynchronous Programming
  7. Project - A Programming Language (review)
  8. ​Exercises - katas

Chess game case

Chess game case

teamplay

Chess game case

reuse code

Chess game case

refactor

Chess game case

navigation

Chess game case

optimization

CommonJS

module.exports

require()

CommonJS

https://repl.it

Get things together

1. Create and export in separate file (weekdayName.js) a function

that returns name of the day based on the provided number

2. List comma separated days of weeks (with your function)

Private?

Export multiple functions

In the same file, add function with months

import weekDays from './weekdays';

Import (ES6 & async)

module.exports = weekdayName; in CommonJS

export default weekdayName; // ES6

import { weekdayNames as days } from './weekdays';

Aliases / destructuring

Find out more...

bit.ly/dojo6-modules-1 (ES6 modules in-depth)

bit.ly/dojo6-modules-2 (modules in the browser)

NPM Packages

Demo

Asynchronous JS

Asynchronous programming is a means of parallel programming in which a unit of work runs separately from the main application thread and notifies the calling thread of its completion, failure or progress…

Examples

Sync vs Async

Sync vs Async

http://ember-concurrency.com/docs/task-concurrency

Sync vs Async

When?

Networking

Games

User interfaces

Where we don't want our app to freeze

Callback

Callback

Lets write a class that will implement upload method that accepts the name of the file and after 3 seconds (simulate upload) it calls callback function that will be assigned to .onSuccess.

Promise

resolve / reject

Get some data...

Try to fetch current weather info for Bielsko-Biała. Use .fetch method

finally

.all()

Load more than one...

async & await

Challenge

Install node

 

&

 

run the code

Challenge

write a server with http module that always returns "Hello world" at port 3000

Thanks =)

spread the word...

http://poslinski.net

Dawid Poslinski             PoslinskiNet

Od zera do JavaScript developera #6

By Dawid Pośliński

Od zera do JavaScript developera #6

Porozmawiamy o modułach i jak ugryźć asynchroniczność w JS.

  • 1,044