-
Notifications
You must be signed in to change notification settings - Fork 4
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
addon rewrite #10
addon rewrite #10
Conversation
@miguelcobain this is fantastic - thanks so much! I agree, at least a minor version bump. Actually, https://github.com/shipshapecode/ember-assign-polyfill suggests a major version bump - fine with me. I'll also add a note about compatibility to the README. Probably won't get to this until next week though. |
@mminkoff I'm planning to also PR a bump to the filestack-js version (the one we're using is pretty outdated now). |
Terrific - I'll wait for that then. Thanks again for taking care of this, and so neatly. |
I updated the PR to use ember-auto-import instead of the complicated broccoli logic on index.js file. Also updates the fastboot checks to conform fastboot documentation. |
@miguelcobain that's fantastic! Do you still have more coming or is it ready for release? Oh, btw, do you know if those on Ember versions prior to 2.5 can make it work by adding the ember-assign-polyfill? |
@mminkoff yes, if the host app adds the polyfill it should be compatible.
since we're doing a major version bump, I'd like to propose some changes to the API. I'm writing them up in a following comment. If you endorse the proposal, I can go ahead and do it. |
<FilestackPiker @accept=".pdf" @anotherOption="value"/> instead of <FilestackPiker @options={{hash accept=".pdf" anotherOption="value"}}/> We would allow an <FilestackPiker @accept=".pdf" @options={{options}}/>
{{!--
`options` is a hash from a controller.js file, for example.
In this example, if `options.accept` is defined, it would be overwritten
with `".pdf"` value, since it was explicitly passed in.
--}}
//config/environment.js
module.exports = function(environment) {
var ENV = {
//...
'ember-filestack': {
apiKey: '<your-filestack-key>',
pickerOptions: {
imageMax: [999, 999],
imageMin: [100, 100],
storeTo: { ... },
// any other picker options here
},
clientOptions: {
cname: 'example.com',
sessionCache: true,
// any other client options here
}
};
//...
} Using the addon name as the key is a common pattern in ember addons, e.g ember-bootstrap, ember-paper, etc.
To take advantage of this, we would need to allow any TransformOptions a direct argument to the In my opinion,
I'm proposing a new component the would be used as <FilestackPreview @handle={{file.handle}} /> This component would have all the PreviewOptions in the same manner that
This was a long one. :) |
@mminkoff I pushed all the suggestions I wrote above, hope you don't mind. I think some of the CDN features are now obsolete since filestack doesn't use This is quite a lot to review. I think the easiest way would be for you to read the updated README to see what is new! Here it is: Also tagging @scudco(the second major contributor). The more eyes we get on this, the better. Overall, I think the addon is way simpler with this, with much less code and more features. Thanks everyone. |
@miguelcobain Sorry not to have gotten back to you sooner. Overall, I love what you've done (I haven't looked at the code yet but I assume for the moment that it's as excellent as your approach). I look forward to getting to use it. I do have some thoughts though:
Again, this really looks marvelous and I'm excited to have this be brought up to date! Great work! |
Ok, I updated some instructions about ember compatibility.
Indeed, that would be too much effort, maybe even impossible since the filestack-js version has changed. What do you think about writing a migration guide? |
I like the update to the Readme - thanks for that. A migration guide sounds like the right answer. I'd love to do it but I'm in the middle of a crunch that might take a few weeks. If I find some extra time I can try to make it happen but I'm reluctant to commit to doing it soon. Can you stand waiting a few weeks? |
@mminkoff I got this. :) |
OK, if you write it then I can find time to give it a try on my own app in the next few days. I'd like to give it a test run before publishing it, ok? |
That would be awesome. 👍 |
wew that's a lot of code. We needed to upgrade to the latest filestack-js a few months ago so we wrote a service for filestack using I don't really have time to offer any opinions or thoughts on this PR, but here's what we ended up with. I had meant to share it when we wrote it to see if this addon could just be EOL'd, but got plenty distracted. config/environment.js let ENV = {
// ...
filestack: {
apiKey: 'my-filestack-key',
processCdn: 'https://special-process-cdn.cloudfront.net',
contentCdn: 'https://special-content-cdn.cloudfront.net',
},
// ... app/services/filestack.jsimport * as filestack from 'filestack-js';
import Service from '@ember/service';
import scrub from 'app/utils/scrub';
import { computed } from '@ember/object';
import { getOwner } from '@ember/application';
import { last } from 'lodash';
const defaultContentCdn = "https://cdn.filestackcontent.com";
const defaultProcessCdn = "https://process.filestackapi.com";
export const defaultPickerOptions = {
accept: ['image/*'],
maxSize: 10*1024*1024,
};
export default Service.extend({
defaultPickerOptions,
contentCdnRegex: computed('contentCdn', function() {
return new RegExp(`^(${defaultContentCdn}|${this.contentCdn})`);
}),
processCdnRegex: computed('processCdn', function() {
new RegExp(`^(${defaultProcessCdn}|${this.processCdn})`);
}),
init() {
this._super(...arguments);
let ENV = getOwner(this).resolveRegistration('config:environment');
this.set('apiKey', ENV.filestack.apiKey);
this.set('contentCdn', ENV.filestack.contentCdn || defaultContentCdn);
this.set('processCdn', ENV.filestack.processCdn || defaultProcessCdn);
this.set('instance', filestack.init(this.apiKey));
},
imageUrl(handleOrUrl, transformations={}) {
if (!handleOrUrl) { return ''; }
transformations = scrub(transformations);
let handle, url, urlWithTransforms;
let isFilestackContentUrl = handleOrUrl.match(this.contentCdnRegex);
if (isFilestackContentUrl) {
handle = last(handleOrUrl.split('/'));
} else {
url = handleOrUrl;
}
if (Object.keys(transformations).length) {
urlWithTransforms = this.instance.transform(handle || url, transformations);
if (urlWithTransforms.match(this.contentCdnRegex)) {
return urlWithTransforms.replace(this.contentCdnRegex, this.contentCdn);
} else if (urlWithTransforms.match(this.processCdnRegex)) {
return urlWithTransforms.replace(this.processCdnRegex, this.processCdn);
} else {
return urlWithTransforms;
}
} else if (handle) {
return [this.contentCdn, handle].join('/');
} else {
return url;
}
},
}); app/helpers/filestack-image.jsimport Helper from '@ember/component/helper';
import { inject as service } from '@ember/service';
export default Helper.extend({
filestack: service(),
compute([handleOrUrl], transformations) {
return this.filestack.imageUrl(handleOrUrl, transformations);
}
}); then in our components when we need access to the configured filestack instance Component Snippet filestack: service(),
didReceiveAttrs() {
this._super(...arguments);
this.set('options', assign({}, this.filestack.defaulPickerOptions));
filestackPickerEvents.forEach((eventName) => {
this.set(`options.${eventName}`, this.get(eventName).bind(this));
});
},
didInsertElement() {
this._super(...arguments);
this.set('picker', this.filestack.instance.picker(this.options));
}, From a quick glance it seems @miguelcobain has created a much more fleshed out, addon-worthy set of changes than our purpose-built implementation. @mminkoff Hope this is at least some help and further proof that the |
@scudco I did find all of that very helpful - thanks so much for taking the time to put it together. I'm glad to hear that |
@scudco from my investigations, filestack doesn't seem to be using process urls anymore. All files, even if they have transforms, are accessed through the normal cdn. |
@miguelcobain yeah you should feel free to ignore the implementation of |
@mminkoff I added a migration guide: https://github.com/miguelcobain/ember-filestack/blob/update-dependencies/MIGRATION.md Let me know if you need something else from me. |
There's actually one last thing. As the That means that, if we don't add it, it would fail on older browsers. I asked on ember's discord for how to proceed, but the solution will be to fix ember-cli-promise-polyfill to polyfill ember versions correctly. |
The migration guide looks great. Small thing - let's make the handleOrUrl parameter the same in the old and new versions - some folks might think that parameter name matters somehow. What do you mean the solution will be to fix ember-cli-promise-polyfill to polypill ember versions correctly? Are you suggesting that we're dependent on a change there in order to push this comfortably, or for it to work in older versions? |
Nice catch. Updated.
ember-filestack will depend on ember-cli-promise-polyfill. Right now that addon is kind of in a broken state because it doesn't add the polyfill on versions below 3.4 to prevent adding multiple promise implementations. Meanwhile, this PR should work fine on any browser that supports Promises natively. |
So do you suggest waiting for the fixed polyfill or perhaps putting a note in the README that you shouldn't update to the new version if you target older browsers? |
I suggest we wait a little bit more. :) |
Works for me. I won't be able to test this out until next week. |
@mminkoff Ok, so I added the polyfill. Everything seems good to merge for me! |
@miguelcobain I just went through the migration docs and it was super-easy! One thing, though. As easy as it is to do the updates, there's no real upside (other than not doing the work) to not supporting an easier upgrade path. So I'd like to do the following before releasing this as 2.0.0: A. Support the old I've gone back and forth with myself over this, and while I have some reluctancy about it, I think it's the right thing to do. Any objection or other thoughts? Oh, btw, in the migration guide, you have I'll be happy to make the above changes if you'd like. |
Ok, I fixed that. Regarding the upgrade path, my latest commit adds the following:
Well, I think this covers the entire migration guide, basically. :) My suggestion is to release this as This conforms very nicely with ember's philosophy of "if you're running pre-major versions without deprecations, you should just be able to upgrade to the next major version without issues". |
Wow - amazing! Yes, exactly right - you can upgrade to the next version if you don't get any deprecations. One thing though - the ember-assign-polyfill docs suggest a major version bump when it's removed, which seems fair to me, and while it won't have an advance deprecation notice, it'll be easy enough to add the polyfill back if they need it. So I think this should be 2.0.0 and we'll remove this training wheels, so to speak, for 3.0.0. Did you put an "until" in the deprecation notices? We'd want those to say 3.0.0. |
@mminkoff I see. You're suggesting two major bumps. I guess that's safer. 👍 |
Fantastic - really excellent work @miguelcobain! Thanks so much for the diligence, high quality, and friendliness. |
@miguelcobain I'm going to add a reference in the README to the Filestack API changelog given that we've updated |
You're very welcome. Glad I could help. :) Sounds good. Once 2.0 is out I can PR the removal of deprecated features. |
Terrific, though I probably wouldn't pull it until there's a reason to go to 3.0.0. I don't see any reason to be in a rush to take out the deprecated features, do you? |
I don't see a reason to not do it either, I think, and we save a few bytes on people's builds (definitely not the major argument). The addon is essentially feature complete now, so I don't foresee any major new features coming. |
@miguelcobain it's now published! Note that I had to change the integration tests back to using handlebars instead of angle brackets to get the tests to work. |
This PR:
Ember
global)This drops support for ember versions prior to 2.5 due to the removal of ember assign polyfill. At least a minor version bump should be done.