Slide 1

Slide 1 text

A new JavaScript ecosystem for Symfony

Slide 2

Slide 2 text

Hello! I am Titouan Galopin SymfonyInsight Product Manager Symfony UX initiative lead 2

Slide 3

Slide 3 text

JavaScript 3

Slide 4

Slide 4 text

JavaScript is about User Experience Building the most intuitive and usable app to solve a specific problem 4

Slide 5

Slide 5 text

Building great User Experiences is difficult We need to rely on the work of others : the JavaScript ecosystem 5

Slide 6

Slide 6 text

Symfony does not choose for you Since Symfony 2 (2011), Symfony is JavaScript agnostic 6

Slide 7

Slide 7 text

And that’s good! There is no clear framework winner: we should not be tied to a specific one 7

Slide 8

Slide 8 text

Today, 2 JavaScript options for Symfony applications ⬡ Vanilla JavaScript ∙ Webpack entrypoints ∙ Vanilla JS/jQuery ∙ Manual libraries 8

Slide 9

Slide 9 text

Today, 2 JavaScript options for Symfony applications ⬡ Vanilla JavaScript ∙ Webpack entrypoints ∙ Vanilla JS/jQuery ∙ Manual libraries 9 ⬡ Single Page Apps ∙ React/Vue/Angular/… ∙ Local router, database, cache, API client, ... ∙ Reimplements history, session, loaders, ...

Slide 10

Slide 10 text

Both add complexity and are difficult to maintain* They take valuable time 10 *I did an entire talk about this

Slide 11

Slide 11 text

How to decrease the time required to build great User Experiences? 11

Slide 12

Slide 12 text

Symfony UX initiative 12 A new series of tools to build User Experiences with Symfony

Slide 13

Slide 13 text

13 What do we actually want?

Slide 14

Slide 14 text

What do we actually want? 1. Organizing JavaScript code inside our projects 14

Slide 15

Slide 15 text

What do we actually want? 1. Organizing JavaScript code inside our projects 2. Avoiding complexity as much as possible 15

Slide 16

Slide 16 text

What do we actually want? 1. Organizing JavaScript code inside our projects 2. Avoiding complexity as much as possible 16 3. Relying on code developed by others

Slide 17

Slide 17 text

What do we actually want? 1. Organizing JavaScript code inside our projects 2. Avoiding complexity as much as possible 17 3. Relying on code developed by others 4. Implementing great User Experiences

Slide 18

Slide 18 text

What are our constraints? Not tied to a framework (compatible with React/Vue/...) 18

Slide 19

Slide 19 text

What are our constraints? Not tied to a framework (compatible with React/Vue/...) Based on standards (history, URL, sessions, cookies, …) 19

Slide 20

Slide 20 text

What are our constraints? Not tied to a framework (compatible with React/Vue/...) Based on standards (history, URL, sessions, cookies, …) 20 Easy to test automatically (unit and functional: cf Cypress talk)

Slide 21

Slide 21 text

What are our constraints? Not tied to a framework (compatible with React/Vue/...) Based on standards (history, URL, sessions, cookies, …) 21 Easy to test automatically (unit and functional: cf Cypress talk) As simple as possible (=== as less code as possible)

Slide 22

Slide 22 text

The Symfony UX initiative ⬡ Stimulus Organizing JavaScript code in Symfony projects ⬡ Flex and Webpack Encore Shipping reusable JavaScript code with Symfony bundles ⬡ Swup/Turbolinks A new approach on building great UX experiences based on standards 22

Slide 23

Slide 23 text

Stimulus “A modest JavaScript framework for the HTML you already have” 23

Slide 24

Slide 24 text

Stimulus does not take over your application’s entire front-end It augments your existing HTML by connecting DOM nodes to JavaScript behaviors automatically 24

Slide 25

Slide 25 text

I usually think of Stimulus as a Router for DOM nodes => It associates DOM nodes to JavaScript behaviors 25

Slide 26

Slide 26 text

26 Add markers on your normal HTML

Slide 27

Slide 27 text

27 Use these markers to retrieve the DOM nodes in JavaScript Add markers on your normal HTML

Slide 28

Slide 28 text

28 Use these markers to retrieve the DOM nodes in JavaScript Add markers on your normal HTML

Slide 29

Slide 29 text

29 Then that’s normal JavaScript!

Slide 30

Slide 30 text

30 Then that’s normal JavaScript! Which means you can use Vue

Slide 31

Slide 31 text

31 Then that’s normal JavaScript! Which means you can use Vue … or React

Slide 32

Slide 32 text

32 Then that’s normal JavaScript! Which means you can use Vue … or React … or plain JS!

Slide 33

Slide 33 text

33 Then that’s normal JavaScript! Which means you can use Vue this.element = data-controller node … or React … or plain JS!

Slide 34

Slide 34 text

34 A new JavaScript organization for Symfony apps

Slide 35

Slide 35 text

35 A new JavaScript organization for Symfony apps App controllers automatically registered in app.js

Slide 36

Slide 36 text

36 A new JavaScript organization for Symfony apps App controllers automatically registered in app.js All controllers shipped as a single compiled JavaScript file

Slide 37

Slide 37 text

37 A new JavaScript organization for Symfony apps App controllers automatically registered in app.js All controllers shipped as a single compiled JavaScript file A single entrypoint referenced in all pages using WebpackEncoreBundle

Slide 38

Slide 38 text

Automatically configured by Symfony Flex 38

Slide 39

Slide 39 text

What do we actually want? 2. Avoiding complexity as much as possible ✔ 39 3. Relying on code developed by others 4. Implementing great User Experiences 1. Organizing JavaScript code inside our projects ✔

Slide 40

Slide 40 text

Flex and Encore Creating a bridge between back-end and front-end to build reusable UX packages 40

Slide 41

Slide 41 text

Example Symfony UX Dropzone 41

Slide 42

Slide 42 text

42 Usage

Slide 43

Slide 43 text

43 When you install a package containing JavaScript code, Symfony Flex detects it Usage

Slide 44

Slide 44 text

44 Usage

Slide 45

Slide 45 text

And that’s it! Flex did most of the work 45

Slide 46

Slide 46 text

46 When you require ux-dropzone ...

Slide 47

Slide 47 text

47 When you require ux-dropzone ... … Flex adds a reference to ux-dropzone’s JavaScript code in your package.json ...

Slide 48

Slide 48 text

48 When you require ux-dropzone ... … and adds a reference to ux-dropzone’s Stimulus controller in your assets/controllers.json … Flex adds a reference to ux-dropzone’s JavaScript code in your package.json ...

Slide 49

Slide 49 text

ux-dropzone now has access to its controllers through your app’s JavaScript They are compiled into your application JavaScript: ux-dropzone can use them in its PHP/Twig code 49

Slide 50

Slide 50 text

50

Slide 51

Slide 51 text

How it works internally 51

Slide 52

Slide 52 text

52 ux-dropzone contains JavaScript code in an assets directory ...

Slide 53

Slide 53 text

53 … and declares the controllers it provides in assets/package.json ux-dropzone contains JavaScript code in an assets directory ...

Slide 54

Slide 54 text

54 On install Flex reads ux-dropzone’s package.json and update your package.json and controllers.json

Slide 55

Slide 55 text

55 On install Flex reads ux-dropzone’s package.json and update your package.json and controllers.json Then WebpackEncore reads your controllers.json and dynamically resolve vendor controllers ...

Slide 56

Slide 56 text

56 … so that the Stimulus bridge can add them to the compilation On install Flex reads ux-dropzone’s package.json and update your package.json and controllers.json Then WebpackEncore reads your controllers.json and dynamically resolve vendor controllers ...

Slide 57

Slide 57 text

What do we actually want? 2. Avoiding complexity as much as possible ✔ 57 3. Relying on code developed by others ✔ 4. Implementing great User Experiences 1. Organizing JavaScript code inside our projects ✔

Slide 58

Slide 58 text

Swup/Turbolinks Using pages transitions libraries to build great User Experiences 58

Slide 59

Slide 59 text

Stimulus creates local behaviors (limited to specific DOM nodes) Stimulus alone doesn’t feel “like one app” ... 59

Slide 60

Slide 60 text

That’s where page transition libraries are useful (Turbolinks, Swup, …) 60

Slide 61

Slide 61 text

They replace links by AJAX calls and animate transitions between pages 61

Slide 62

Slide 62 text

Example Symfony UX Swup 62

Slide 63

Slide 63 text

63 Usage

Slide 64

Slide 64 text

64 Usage

Slide 65

Slide 65 text

What do we actually want? 2. Avoiding complexity as much as possible ✔ 65 3. Relying on code developed by others ✔ 4. Implementing great User Experiences ✔ 1. Organizing JavaScript code inside our projects ✔

Slide 66

Slide 66 text

Oh, and one last thing 66

Slide 67

Slide 67 text

Symfony UX initiative is going to be available … 67

Slide 68

Slide 68 text

Symfony UX initiative is going to be available … now! 68

Slide 69

Slide 69 text

symfony.com/ux A few packages are already available 69

Slide 70

Slide 70 text

Now, that’s on you! Let’s build an amazing new ecosystem for Symfony together! 70

Slide 71

Slide 71 text

71 Thanks! Any questions? You can find me at: @tgalopin [email protected] Slides design by SlidesCarnival