Forked from runspired/components.conditional-state.js
Created
October 27, 2017 08:35
-
-
Save kumkanillam/392e6b107a3b96fbf875f580c19a77bb to your computer and use it in GitHub Desktop.
Recycled Route State
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.Component.extend({ | |
init() { | |
this._super(); | |
this.instanceState = "I was created at: " + Date.now(); | |
} | |
}); |
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 { get, set } = Ember; | |
export default Ember.Component.extend({ | |
getContent() { | |
const obj = get(this, 'model'); | |
if (!obj) { return obj; } | |
if (typeof obj === 'object' && obj.content) { | |
return get(obj, 'content'); | |
} | |
return obj; | |
}, | |
didUpdateAttrs() { | |
let newContent = this.getContent(); | |
let isSlotOne = get(this, 'useSlotOne'); | |
if (isSlotOne && newContent !== get(this, 'slotOne')) { | |
set(this, 'slotTwo', newContent); | |
set(this, 'useSlotOne', false); | |
} else if (!isSlotOne && newContent !== get(this, 'slotTwo')) { | |
set(this, 'slotOne', newContent); | |
set(this, 'useSlotOne', true); | |
} | |
}, | |
init() { | |
this._super(); | |
this.useSlotOne = true; | |
this.slotOne = this.getContent(); | |
this.slotTwo = null; | |
} | |
}); |
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('my-route', { path: '/:id' }); | |
}); | |
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({ | |
someRouteState: null, | |
beforeModel() { | |
const params = this.paramsFor(this.routeName); | |
const id = params.id; | |
if (!this.someRouteState || this.someRouteState.routeId !== id) { | |
this.someRouteState = { | |
routeId: id | |
}; | |
} | |
}, | |
model({ id }) { | |
return { | |
id, | |
name: 'I am model ' + id | |
}; | |
}, | |
setupController(controller, model) { | |
this._super(controller, model); | |
Ember.set(controller, 'state', this.someRouteState); | |
} | |
}); |
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.12.1", | |
"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.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment