Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect ember-tether and throw an error early if not present and tetherTarget is passed. #189

Merged
merged 1 commit into from
May 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,27 @@ This can then be used like so:
Custom modal contents
{{/full-screen-modal}}
```
## Using as a nested addon

If you create an addon that you want to depend on ember-modal-dialog, you need to provide for ember-modal-dialog's config hook to run. You do this in the config hook of your addon. Example:

```js
// index.js

module.exports = {
name: 'my-addon',
config: function(environment, appConfig) {
let initialConfig = _.merge({}, appConfig);
let updatedConfig = this.addons.reduce((config, addon) => {
if (addon.config) {
_.merge(config, addon.config(environment, config));
}
return config;
}, initialConfig);
return updatedConfig;
}
};
```

## Dependencies

Expand Down
3 changes: 3 additions & 0 deletions addon/components/modal-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export default Ember.Component.extend({
if (this.get('renderInPlace')) {
return 'ember-modal-dialog/-in-place-dialog';
} else if (this.get('tetherTarget')) {
if (!this.get('modalService.hasEmberTether')) {
throw new Error('Please install ember-tether in order to pass a tetherTarget to modal-dialog');
}
return 'ember-modal-dialog/-tether-dialog';
}
return 'ember-modal-dialog/-basic-dialog';
Expand Down
3 changes: 0 additions & 3 deletions addon/services/modal-dialog.js

This file was deleted.

12 changes: 8 additions & 4 deletions app/services/modal-dialog.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import Ember from 'ember';
import Service from 'ember-modal-dialog/services/modal-dialog';
import ENV from '../config/environment';

const {
computed
} = Ember;
const { computed, Service } = Ember;

function computedFromConfig(prop) {
return computed(function(){
return ENV['ember-modal-dialog'][prop];
});
}

export default Service.extend({
hasEmberTether: computedFromConfig('hasEmberTether'),
destinationElementId: computed(function() {
/*
everywhere except test, this property will be overwritten
Expand Down
13 changes: 11 additions & 2 deletions config/environment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/* eslint-env node */
'use strict';

module.exports = function(/* environment, appConfig */) {
return { };
var VersionChecker = require('ember-cli-version-checker');

module.exports = function( environment, appConfig, addon ) {
appConfig['ember-modal-dialog'] = appConfig['ember-modal-dialog'] || {};

var checker = new VersionChecker(addon);
var hasEmberTether = checker.for('ember-tether', 'npm').version;

appConfig['ember-modal-dialog']['hasEmberTether'] = hasEmberTether;

return appConfig;
};
15 changes: 14 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
/* eslint-env node */
'use strict';

var fs = require('fs');
var path = require('path');

module.exports = {
name: 'ember-modal-dialog'
name: 'ember-modal-dialog',
config: function (env, baseConfig) {
var configPath = path.join(this.root, 'config', 'environment.js');

if (fs.existsSync(configPath)) {
var configGenerator = require(configPath);

return configGenerator(env, baseConfig, this);
}
}

};