Last active
February 20, 2018 10:31
-
-
Save oxodesign/25b37d15db6da59ee8392a4d8c60c1b8 to your computer and use it in GitHub Desktop.
item-hash-2
This file contains 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 Ember from 'ember'; | |
const {computed, get, isEmpty, isBlank, set} = Ember; | |
export default Ember.Component.extend({ | |
name: null, | |
slug: null, | |
init(){ | |
this._super(...arguments); | |
const { name, slug } = this.attrs; | |
if(isBlank(slug)){ | |
set(this, 'slug', Ember.String.dasherize(get(this,'name'))); | |
} | |
this['register-item'](this); | |
}, | |
isActive: computed('manager.currentItem.slug', 'slug', function() { | |
return get(this, 'manager.currentItem.slug') === get(this, 'slug'); | |
}), | |
}); |
This file contains 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 Ember from 'ember'; | |
const {computed, get, isEmpty, isBlank, set} = Ember; | |
export default Ember.Component.extend({ | |
items: [], | |
firstItem: null, | |
lastItem: null, | |
currentItem: null, | |
addItem(item){ | |
let items = get(this, 'items'); | |
if(!items.findBy('slug', get(item, 'slug'))){ | |
if (!get(this, 'firstItem')) { | |
set(this, 'firstItem', item); | |
} | |
if (!get(this, 'currentItem')) { | |
console.log('firstItem'); | |
set(this, 'currentItem', item); | |
} | |
set(this, 'lastItem', item); | |
get(this, 'items').addObject(item); | |
} | |
}, | |
initCurrentItem(){ | |
let slug = get(this, 'currentItemSlug'); | |
let item = get(this, 'items').findBy('slug', slug); | |
if(item){ | |
set(this, 'currentItem', item); | |
} | |
}, | |
didInsertElement() { | |
this._super(...arguments); | |
this.initCurrentItem(); | |
set(this, '_hasRendered', true); | |
}, | |
actions: { | |
'register-item-component'(item) { | |
this.addItem(item); | |
}, | |
'transition-to-slug'(slug) { | |
console.log('ok'); | |
}, | |
} | |
}); |
This file contains 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 Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
This file contains 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 Ember from 'ember'; | |
import config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('another-route'); | |
}); | |
export default Router; |
This file contains 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 Ember from 'ember'; | |
export default Ember.Route.extend({ | |
}); |
This file contains 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
{ | |
"version": "0.13.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.16.2", | |
"ember-template-compiler": "2.16.2", | |
"ember-testing": "2.16.2" | |
}, | |
"addons": { | |
"ember-data": "2.16.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment