github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/app/utils/qp-serialize.js (about) 1 import { computed } from '@ember/object'; 2 3 // An unattractive but robust way to encode query params 4 export const serialize = arr => (arr.length ? JSON.stringify(arr) : ''); 5 6 export const deserialize = str => { 7 try { 8 return JSON.parse(str) 9 .compact() 10 .without(''); 11 } catch (e) { 12 return []; 13 } 14 }; 15 16 // A computed property macro for deserializing a query param 17 export const deserializedQueryParam = qpKey => 18 computed(qpKey, function() { 19 return deserialize(this.get(qpKey)); 20 });