Last active
July 25, 2017 17:38
-
-
Save buschtoens/75b2ce2383f8b6021d2f99e2f5a3818f to your computer and use it in GitHub Desktop.
ember-parachute
This file contains hidden or 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 QueryParams from 'ember-parachute'; | |
export const myQueryParams = new QueryParams({ | |
parachuteOpen: { | |
as: 'parachute', | |
defaultValue: true, | |
}, | |
page: { | |
defaultValue: 1, | |
refresh: true | |
}, | |
search: { | |
defaultValue: '', | |
refresh: true | |
}, | |
tags: { | |
defaultValue: ['Ember', 'Parachute'], | |
refresh: true, | |
serialize(value) { | |
return value.toString(); | |
}, | |
deserialize(value = '') { | |
return value.split(','); | |
} | |
} | |
}); | |
export default Ember.Controller.extend(myQueryParams.Mixin, { | |
queryParamsChanged: Ember.computed.or('queryParamsState.{page,search,tags}.changed'), | |
fetchedDataAt: null, | |
queryParamsDidChange({ shouldRefresh, queryParams }) { | |
// if any query param with `refresh: true` is changed, `shouldRefresh` is `true` | |
if (shouldRefresh) { | |
this.fetchData(queryParams); | |
} | |
}, | |
fetchData(queryParams) { | |
this.set('fetchedDataAt', new Date); | |
}, | |
actions: { | |
resetAll() { | |
// reset all query params to their default values specified in the query param map | |
this.resetQueryParams(); | |
}, | |
updateTag(index, tag) { | |
this.get('tags').replace(index, 1, [tag]); | |
}, | |
pushTag(tag) { | |
this.get('tags').pushObject(tag); | |
}, | |
removeTag(tag) { | |
this.get('tags').removeObject(tag); | |
} | |
} | |
}); |
This file contains hidden or 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", | |
"ember-parachute": "0.2.2", | |
"ember-one-way-controls": "2.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment