react and vanilla js - developermarch€¦ · react and vanilla js the fight for domination samdish...

30
React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan

Upload: others

Post on 22-May-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

React and Vanilla JSThe Fight for DOMination

Samdish Suri @awreccan

Page 2: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU
Page 3: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU
Page 4: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU
Page 5: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

WHAT IF

YOU COULD DRAG ITEMS TO OTHER LISTS?

Page 6: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU
Page 7: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU
Page 8: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

WHAT IF I TOLD YOU

THERE’S A LIBRARY FOR THAT

Page 9: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU
Page 10: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

it’s the perfect DOM manipulation pluginbut it’s pure Vanilla JS

without a React wrapper

!

that shouldn’t be a problem "

Page 11: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU
Page 12: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU
Page 13: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

Sunshine and daisies and unicorns

Page 14: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

Redux Action

Redux State

React vDOM

Muuri DOM

Unmount the original

Copy it

Drag it

Drop it

Mount a new node

dragging:

# ➡ %

dragging:

% ➡ #

DRAG_ITEM

DROP_ITEM

&

Page 15: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

State (Redux) UI (React)

Changes in the State refresh the UI

User uses the UI to update the State

Page 16: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

State (Redux) UI (React)

Changes in the State refresh the UI

User uses the UI to update the State

MuuriUI (React)

User uses Muuri to update the UI

Page 17: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

State (Redux) UI (React)

Changes in the State refresh the UI

User uses the UI to update the State

MuuriUI (React)

User uses Muuri to update the UI

Sync Muuri’s UI changes to State

Renders a duplicate item (undraggable)

Page 18: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

Redux Action

Redux State

React vDOM

Muuri DOM

Unmount the original

Copy it

Drag it

Drop it

Mount a new node

dragging:

# ➡ %

dragging:

% ➡ #

DRAG_ITEM

DROP_ITEM

&

Render DOM node

Make it draggableMount

the fixMake the React node draggable

Page 19: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

Redux Action

Redux State

React vDOM

Muuri DOM

Unmount the original

Copy it

Drag it

Drop it

Mount a new node

dragging:

# ➡ %

dragging:

% ➡ #

DRAG_ITEM

DROP_ITEM

&

Render DOM node

Make it draggableMount

the fixMake the React node draggable

& Unmount the dragged node

Page 20: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

OR ensure that you bring React (vDOM) and the DOM back in sync

Page 21: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

State (Redux) UI (React)

Changes in the State refresh the UI

User uses the UI to update the State

MuuriUI (React)

User uses Muuri to update the UI

Sync Muuri’s UI changes to State

Renders a duplicate item (undraggable)

Fix this creatively

Page 22: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

Stacking Context

image source: tympanus.net, quote source: MDN

The z-index values of child stacking contexts only have meaning in the parent. Stacking contexts are treated atomically as a single unit in the parent stacking context.

Page 23: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU
Page 24: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

has open menu

Page 25: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

DiagnosisReact vDOM Muuri React

list list-id

time

+ MUURI-DRAGGABLE-ITEM + muuri-item-shown

+ stack-higher

Page 26: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

DiagnosisReact vDOM Muuri React

list list-id write without read (

time

+ MUURI-DRAGGABLE-ITEM + muuri-item-shown

+ stack-higher

Page 27: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

Class WarfareSolutions?

Page 28: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

Class WarfareSolutions?

inline style

has open menu

Page 29: React and Vanilla JS - DeveloperMarch€¦ · React and Vanilla JS The Fight for DOMination Samdish Suri @awreccan. WHAT IF YOU COULD DRAG ITEMS TO OTHER LISTS? WHAT IF I TOLD YOU

React and Vanilla JSThe Fight for DOMination

github.com/awreccan/assigner

Samdish Suri @awreccan