Last active
January 30, 2019 15:41
-
-
Save sukima/55fabb7c1cef425ca16a1176abcde415 to your computer and use it in GitHub Desktop.
Confirmer Wizard Example
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 Component from '@ember/component'; | |
import { computed } from '@ember/object'; | |
export default Component.extend({ | |
tagName: 'pre', | |
classNames: ['json-output'], | |
output: computed('json', function() { | |
return JSON.stringify(this.json, null, 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 Component from '@ember/component'; | |
import { computed } from '@ember/object'; | |
import Confirmer from 'confirmer'; | |
const STEPS = Object.freeze({ | |
ONE: 'one', | |
TWO: 'two', | |
THREE: 'three' | |
}); | |
const STEP_TITLES = Object.freeze({ | |
[STEPS.ONE]: 'Step One', | |
[STEPS.TWO]: 'Step Two', | |
[STEPS.THREE]: 'Step Three' | |
}); | |
export default Component.extend({ | |
STEPS, STEP_TITLES, | |
stepMap: computed('currentStep', function() { | |
return { [this.currentStep]: true }; | |
}), | |
openModal() { | |
return new Confirmer(resolver => { | |
this.setProperties({ resolver, result: {} }); | |
resolver.dispose(() => { | |
this.setProperties({ resolver: null, result: null }); | |
}); | |
this.waitForStepOne() | |
.onConfirmed(() => resolver.confirm(this.result)) | |
.onRejected(resolver.reject) | |
.onCancelled(resolver.cancel) | |
.catch(resolver.error); | |
}); | |
}, | |
waitForStep(currentStep) { | |
return new Confirmer(stepResolver => { | |
this.setProperties({ stepResolver, currentStep }); | |
}).onConfirmed(v => this.result[currentStep] = v); | |
}, | |
waitForStepOne() { | |
return this.waitForStep(STEPS.ONE) | |
.onConfirmed(() => this.waitForStepTwo()); | |
}, | |
waitForStepTwo() { | |
return this.waitForStep(STEPS.TWO) | |
.onConfirmed(() => this.waitForStepThree()) | |
.onRejected(() => this.waitForStepOne()); | |
}, | |
waitForStepThree() { | |
return this.waitForStep(STEPS.THREE) | |
.onRejected(() => this.waitForStepTwo()); | |
}, | |
didInsertElement() { | |
this._super(...arguments); | |
this.registerManager({ | |
open: () => this.openModal(), | |
confirm: v => this.resolver.confirm(v), | |
reject: v => this.resolver.reject(v), | |
cancel: v => this.resolver.cancel(v), | |
error: err => this.resolver.error(err) | |
}); | |
}, | |
actions: { | |
resolve(method, value) { | |
this.stepResolver[method](value); | |
} | |
} | |
}); |
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 Controller from '@ember/controller'; | |
export default Controller.extend({ | |
wizardResult: "Wizard has not been opened yet.", | |
actions: { | |
async showWizard() { | |
try { | |
this.set('wizardRunning', false); | |
let result = await this.wizardManager.open(); | |
this.set('wizardResult', result); | |
} finally { | |
this.set('wizardRunning', false); | |
} | |
} | |
} | |
}); |
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.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"spectre_css": "https://unpkg.com/spectre.css/dist/spectre.min.css", | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-data": "3.4.2", | |
"ember-confirmed": "2.5.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment