applying microservices principles to front end

50
Community Partners

Upload: ahmed-elharouny

Post on 28-Jan-2018

251 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Applying microservices principles to front end

Community Partners

Page 2: Applying microservices principles to front end
Page 3: Applying microservices principles to front end

Frontend (SPA)

API Gateway

svc svc svc svc

Page 4: Applying microservices principles to front end
Page 5: Applying microservices principles to front end

API Gateway

svc svc svc svc

APP APP APP APP

Page 6: Applying microservices principles to front end
Page 7: Applying microservices principles to front end
Page 8: Applying microservices principles to front end

• Simple interface

Page 9: Applying microservices principles to front end

• Composition reduces complexity

Page 10: Applying microservices principles to front end

• One flow on information

Page 11: Applying microservices principles to front end

• Different domains• Different technologies• Different release cycles• Isolation• Ownership• Easy integration

Page 12: Applying microservices principles to front end

<iframe>

window.open

window.postMessage

Page 13: Applying microservices principles to front end

• Iframes and popups• Too much static.• Difficult communication.• Doesn’t inherit styles.• Browsers behaving very differently, i.e. popups open in a full page.• Slower to load.

• window.postMessage• Browsers behaving differently, i.e. IE 11 < will prevent window-to-window.• Fire and forget.• One huge event handler where all messages are delivered.• Difficult to secure communication.

Page 14: Applying microservices principles to front end

window.parent.postMessage(‘Get user token’, ‘*’);

https://www.mysite.com

https://product.mysite.com

Page 15: Applying microservices principles to front end

https://www.mysite.com

https://product.mysite.com

message.source.postMessage(‘User token: XYZ’, *);

window.parent.postMessage(‘Get user token’, ‘*’);

Page 16: Applying microservices principles to front end

https://www.mysite.com

https://product.mysite.comhttps://www.hacker-site.com

window.parent.postMessage(‘Send user token’, ‘*’);

window.parent.postMessage(‘Get user token’, ‘*’);

Page 17: Applying microservices principles to front end

• Safely allow cross-origin communication between different pages.

Page 18: Applying microservices principles to front end

• Safely allow cross-origin communication between different pages.

Page 19: Applying microservices principles to front end
Page 20: Applying microservices principles to front end

• Abstract rendering into:• Iframe• Window

• Provides a simple component-like contract.• Supporting passing properties down,

actions up.• Securely handle communication.• Technology specific adapters.

Page 21: Applying microservices principles to front end
Page 22: Applying microservices principles to front end
Page 23: Applying microservices principles to front end
Page 24: Applying microservices principles to front end

https://github.com/harouny/luxor

Page 25: Applying microservices principles to front end

• Host pass down props.• Component bubble up events.• Component subscribe to props change to update internal state.

• Updating component internal state trigger UI changes.• Host can update props based on events.

One flow of data

Page 26: Applying microservices principles to front end

Set Props

On Props

Raise event

On event

Set Props

On Props

Raise event

On event

Host

Component

Page 27: Applying microservices principles to front end
Page 28: Applying microservices principles to front end

1

3

2

Page 29: Applying microservices principles to front end

1

2

3

Page 30: Applying microservices principles to front end
Page 31: Applying microservices principles to front end
Page 32: Applying microservices principles to front end
Page 33: Applying microservices principles to front end
Page 34: Applying microservices principles to front end
Page 35: Applying microservices principles to front end
Page 36: Applying microservices principles to front end
Page 37: Applying microservices principles to front end
Page 38: Applying microservices principles to front end
Page 39: Applying microservices principles to front end
Page 40: Applying microservices principles to front end
Page 41: Applying microservices principles to front end
Page 42: Applying microservices principles to front end

• Xcomponent is not meant to replace native components.• Use it to share complete functionality.• Keeps contract simple.

Page 43: Applying microservices principles to front end

• Bundle Xcomponent library with component definition in one script.• Simple integration.

• Use Webpack for bundling.

Page 44: Applying microservices principles to front end

• Angular digest cycle, change detection.• Event handlers (functions) are executed outside of angular

context.• Native drivers helps to avoid the problem.

Page 45: Applying microservices principles to front end

• Xcomponent uses some built-in props.• onEnter• onRender• onClose• LogLevel

Page 46: Applying microservices principles to front end

• “this” in event handlers (functions).• Bound to component instance even if you don’t think so, i.e.

inside a class.

Page 47: Applying microservices principles to front end

• IE < 11 prevent communication with popups in a different domain.• Iframe bridge is required (configuration)

Page 48: Applying microservices principles to front end

• Xcomponent brings the best of both worlds of:• Native components

• Simple contract• Communication style

• Cross domain components• Isolation• Flexibility• Technology independence

Page 49: Applying microservices principles to front end
Page 50: Applying microservices principles to front end