Created
April 13, 2017 20:22
-
-
Save DingoEatingFuzz/6b44c32b11dde3c9b253b07db551339b to your computer and use it in GitHub Desktop.
Tours Data Structure Proposal
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 Tour from '../tour-model'; | |
const { inject } = Ember; | |
export default Ember.Controller.extend({ | |
personalization: inject.service(), | |
campaignTour: null, | |
initializeTour: function() { | |
this.set('campaignTour', Tour.create({ | |
name: 'campaign', | |
personalization: this.get('personalization'), | |
})); | |
}.on('init'), | |
appName: 'Ember Twiddle', | |
actions: { | |
startCampaign() { | |
this.get('campaignTour').start(); | |
} | |
} | |
}); |
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.Service.extend({ | |
flags: {}, | |
setFlag(flag, value) { | |
const flags = this.get('flags'); | |
const parts = flag.split('.'); | |
parts.forEach((part, i) => { | |
const joined = parts.slice(0, i+1).join('.'); | |
typeof get(flags, joined) === 'object' || set(flags, joined, {}) | |
}); | |
set(flags, `${flag}`, value); | |
console.log('set the flag via the service'); | |
console.log(flags); | |
} | |
}); |
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.Object.extend({ | |
personalization: null, | |
name: '', | |
started: false, | |
aborted: false, | |
completed: false, | |
start() { | |
Ember.assert('Tours need names!', this.get('name')); | |
Ember.assert('Tours need a personalization adapter!', this.get('personalization')); | |
this.set('started', true); | |
this.get('personalization').setFlag(`${this.get('name')}.started`, true); | |
} | |
}); |
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