Last active
May 14, 2017 16:03
-
-
Save etuchscherer/e7d896abcd60dbfdea8ae699f7779e91 to your computer and use it in GitHub Desktop.
Flow-Master
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', | |
flow: Ember.inject.service(), | |
routes: Ember.computed.readOnly('flow.routes'), | |
}); |
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 Model from 'ember-data/model'; | |
import attr from "ember-data/attr"; | |
export default Model.extend({ | |
title: attr('string'), | |
routes: attr() | |
}); |
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({ | |
setupController() { | |
let data = {title: 'myRoute', routes: [1,2,3,4,5]}; | |
} | |
}); | |
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 Service from 'ember-service'; | |
import computed from 'ember-macro-helpers/computed'; | |
import set from 'ember-metal/set'; | |
import get from 'ember-metal/get'; | |
import { readOnly } from 'ember-computed'; | |
export default Service.extend({ | |
// the flow model | |
flow: null, | |
// number of times the | |
// service has been flushed | |
flushCount: 0, | |
routes: readOnly('flow.routes'), | |
isFirst: computed('_currentIndex', 'routes', 'flushCount', { | |
get(index) { | |
return index === 0; | |
} | |
}), | |
isLast: computed('_currentIndex', 'routes', 'flushCount', { | |
get(index, collection) { | |
let lastItem = get(collection, 'length') - 1; | |
return index === lastItem; | |
} | |
}), | |
currentRoute: computed('_currentIndex', 'routes', 'flushCount', { | |
get(index, collection) { | |
return collection[index]; | |
} | |
}), | |
nextRoute: computed('_currentIndex', 'routes', 'isLast', 'flushCount', { | |
get(index, collection, isLast) { | |
if (!isLast) { | |
return collection[index + 1]; | |
} else { | |
return null; | |
} | |
} | |
}), | |
_currentIndex: computed(), | |
reset(flow) { | |
let isSet = set(this, 'flow', flow); | |
if (isSet) { | |
this.incrementProperty('flushCount'); | |
set(this, '_currentIndex', 0); | |
} | |
}, | |
next() { | |
let _currentIndex = get(this, '_currentIndex'); | |
_currentIndex.incrementProperty(); | |
} | |
}); |
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