Skip to content

Instantly share code, notes, and snippets.

View lifeart's full-sized avatar
🐹
Working from home

Alex Kanunnikov lifeart

🐹
Working from home
View GitHub Profile
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
@lifeart
lifeart / EmberStyleAngularController.js
Last active March 4, 2020 01:47
Angular Simple DI for controller ES6
class AngularController {
static injections() {
return ['$scope', 'lodash', '$moment', '$timeout'];
}
static requredInjections() {
return ['lodash', '$timeout'];
}
static getInjections() {
let injections = this.injections();
this.requredInjections().map(injectionName => {
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'iframe',
attributeBindings: ['sandbox','src'],
src: Ember.computed(function(){
return '';
}),
sandbox: 'allow-scripts allow-same-origin allow-popups allow-top-navigation allow-forms',
didRender() {
const doc = this.$()[0].contentDocument || this.$()[0].contentWindow.document;
@lifeart
lifeart / TestData.js
Last active September 6, 2017 11:49
WebWorker JSON Parse - async json parsing
console.log('Starting...');
console.time('Buiding test Data');
const jsonData = {data:new Array(9000000)};
for (let i = 0; i < 9000000; i++) {
jsonData.data.push(`el-${i}`);
}
const dataString = JSON.stringify(jsonData);
console.timeEnd('Buiding test Data');
const interval = setInterval(()=>{
console.log(`${Date.now()} - event loop not blocked`);
@lifeart
lifeart / application.js
Created July 4, 2017 16:37
Ember.adapters
import DS from 'ember-data';
import Ember from 'ember';
const {get, A, isArray} = Ember;
export default DS.JSONAPIAdapter.extend({
host: 'http://mysite.com/data',
pathMap: {
'query:partner-video': 'wm2/get_videos',
'query:partner-payment': 'wm2/get_payments',
'findAll:partner-video': 'wm2/get_videos',
'updateRecord:partner-video': 'wm2/set_file_info',
@lifeart
lifeart / model.js
Created July 4, 2017 16:41
Application model serializer
import DS from 'ember-data';
import ClubSerializer from '../serializers/application';
export default ClubSerializer.extend({
extractAttributes(modelClass, resourceHash) {
var attributes = {};
resourceHash['origin'] = resourceHash.video_id;
resourceHash['file-name'] = resourceHash.file;
resourceHash['thumbnail-offset'] = resourceHash.img;
resourceHash['duration'] = resourceHash.len_val;
@lifeart
lifeart / getargs.js
Created July 14, 2017 22:49
Get fn args name
function getArgs(fn) {
const str = fn.toString();
return str
.slice(str.indexOf('(')+1,str.indexOf(')'))
.split(',')
.map(e=>e.trim());
};
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
a: 1,
b: 2,
c: 3,
d: Ember.computed('a','b','c',function(){
return this.get('a')+this.get('b')+this.get('c');
})
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle1',
a: 3,
b: 4,
c: 5,
d: Ember.computed('a','b','c', function(){
return this.get('a') + this.get('b') + this.get('c');
}),