Top Banner
The Ember.js Run Loop
30
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The Ember.js Run Loop

The Ember.js Run Loop

Page 2: The Ember.js Run Loop

Coalescing Modularity

Performance

Page 3: The Ember.js Run Loop

“the run loop is a mechanism that Ember.js uses to group, coordinate, and execute events, key-value notifications,

and timers within your application.”From Ember.js in Action

Page 4: The Ember.js Run Loop

Queues in the Run Loop

Sync Actions Render AfterRender Destroy

Page 5: The Ember.js Run Loop

Ember implements listeners for each of these queues

Sync Actions Render AfterRender Destroy

Page 6: The Ember.js Run Loop

QUEUE

! !!!

! !

!UPDATE

EVENTS

PREVIOUS QUEUE

NEXT QUEUE

Run Loop

Page 7: The Ember.js Run Loop

Processing each queue can emit events to the proceeding/

preceding queues

Page 8: The Ember.js Run Loop

It’s not an infinite loop

Page 9: The Ember.js Run Loop

Sync Queue: Propagates bound data

Sync Actions Render AfterRender Destroy

Page 10: The Ember.js Run Loop

Actions Queue:Runs Promises

Runs Initialization Events

Sync Actions Render AfterRender Destroy

Page 11: The Ember.js Run Loop

All custom events go to the Actions queue

Sync Actions Render AfterRender Destroy

Page 12: The Ember.js Run Loop

RenderActionsSync AfterRender Destroy

Render Queue:Manipulates DOM Re-renders views

Page 13: The Ember.js Run Loop

AfterRender Queue: Handles extra DOM events

ActionsSync DestroyAfterRenderRender

Page 14: The Ember.js Run Loop

ActionsSync DestroyAfterRenderRender

AfterRender queue is a good place to initialize jQuery plugins on elements

added by the Render queue

Page 15: The Ember.js Run Loop

Destroy Queue: Garbage-collects views

ActionsSync AfterRender DestroyRender

Page 16: The Ember.js Run Loop

Sync Actions Render AfterRender Destroy

Page 17: The Ember.js Run Loop

Sync Actions Render AfterRender Destroy

{ 3 isCompleted Events3 checked events3 remainingFormatted3 markAllDone updates

Page 18: The Ember.js Run Loop

{ 3 checkboxes1 change to status1 change to “Mark all as done”

RenderActionsSync AfterRender Destroy

Page 19: The Ember.js Run Loop

Executing code in the Ember Run Loop

Page 20: The Ember.js Run Loop

$.post(‘/post_cc’, success: function(e) {

Ember.run(function() { this.store.createRecord('user', { cardId: e.data.customerId, planId: 'pro' }); });

});

Executes code immediately by reusing/starting run loop

Page 21: The Ember.js Run Loop

Ember.run.next(function () {

this.set(‘flash’, “Hello world”);

})

Executes code in the next available run loop

Page 22: The Ember.js Run Loop

Ember.run.later(function () {

this.set(‘flash’, “Hello world”);

}, 1000)

Executes code in the next available run loop after 1s

Page 23: The Ember.js Run Loop

Ember.run.schedule('afterRender', this, function () {

this.$().tooltip();

});

Schedules in the “afterRender” queue

Page 24: The Ember.js Run Loop

Schedules once in the “afterRender” queue

Ember.run.scheduleOnce('afterRender', this, function () {

this.$().tooltip();

});

Page 25: The Ember.js Run Loop

Resources

Page 26: The Ember.js Run Loop
Page 27: The Ember.js Run Loop
Page 28: The Ember.js Run Loop

https://github.com/eoinkelly/ember-runloop-handbook

Ember runloop handbook

Page 29: The Ember.js Run Loop

Q&A

Page 30: The Ember.js Run Loop

Thanks!

! @rizwanreza