Created
January 26, 2018 03:01
-
-
Save mhluska/1d54158710ed2815f56856a2efda947d to your computer and use it in GitHub Desktop.
Ember Performance Issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from '@ember/component'; | |
import { computed } from '@ember/object'; | |
import { | |
noop, | |
} from 'lodash'; | |
export default Component.extend({ | |
tagName: 'video', | |
classNameBindings: ['isPlaying'], | |
attributeBindings: ['poster', 'preload', 'src', 'muted', 'loop', 'autoplay'], | |
poster: null, | |
// Meant to be controlled from the parent component if there is play-specific | |
// CSS. This is optional. | |
isPlaying: false, | |
shouldPreload: false, | |
autoplay: false, | |
muted: true, | |
loop: false, | |
volume: 0, | |
onReady: noop, | |
onEnded: noop, | |
onPlaying: noop, | |
preload: computed('shouldPreload', function() { | |
if (this.get('shouldPreload')) { | |
return 'auto'; | |
} else { | |
return 'none'; | |
} | |
}), | |
sendOnReady() { | |
this.get('onReady')(this.element); | |
}, | |
sendOnEnded() { | |
this.get('onEnded')(this.element); | |
}, | |
sendOnPlaying() { | |
this.get('onPlaying')(this.element); | |
}, | |
init() { | |
this._super(...arguments); | |
this.sendOnReady = this.sendOnReady.bind(this); | |
this.sendOnEnded = this.sendOnEnded.bind(this); | |
this.sendOnPlaying = this.sendOnPlaying.bind(this); | |
}, | |
didInsertElement() { | |
this._super(...arguments); | |
this.element.volume = this.get('volume'); | |
this.element.addEventListener('ended', this.sendOnEnded, false); | |
this.element.addEventListener('playing', this.sendOnPlaying, false); | |
if (this.element.readyState >= this.element.HAVE_FUTURE_DATA) { | |
this.sendOnReady(); | |
this.sendOnPlaying(); | |
} else { | |
this.element.addEventListener('canplay', this.sendOnReady, false); | |
} | |
}, | |
willDestroyElement() { | |
this._super(...arguments); | |
this.element.removeEventListener('canplay', this.sendOnReady); | |
this.element.removeEventListener('playing', this.sendOnPlaying); | |
this.element.removeEventListener('ended', this.sendOnEnded); | |
}, | |
mouseEnter() { | |
this.get('onMouseEnter')(this.element); | |
}, | |
mouseLeave() { | |
this.get('onMouseLeave')(this.element); | |
}, | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Route from '@ember/routing/route'; | |
import { inject as service } from '@ember/service'; | |
import RouteStoresShowMixin from 'app/mixins/route-stores-show'; | |
export default Route.extend(RouteStoresShowMixin, { | |
session: service(), | |
currentUser: service(), | |
model(params) { | |
return this.get('store').findRecord('profile', params.profile_id); | |
}, | |
setupController() { | |
const params = this.paramsFor(this.routeName); | |
const controller = this.controllerFor(this.routeName); | |
if (!this.isOwnStore(params.profile_id) && params.isEditing) { | |
controller.set('isEditing', false); | |
} | |
this._super(...arguments); | |
}, | |
resetController(controller, isExiting) { | |
if (isExiting) { | |
controller.set('isEditing', false); | |
} | |
}, | |
isOwnStore(profileId) { | |
return this.get('session.isAuthenticated') && | |
this.get('currentUser.profile.id') === profileId; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment