Skip to content

Commit

Permalink
[fix] Tests passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
bevacqua committed Jun 29, 2016
1 parent dda84e9 commit 41b0651
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/ui/public/metadata.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import _ from 'lodash';
// singleton for immutable copy of window.__KBN__
import $ from 'jquery';

if (!_.has(window, '__KBN__')) {
throw new Error('window.__KBN__ must be set for metadata');
}

const kbn = _.cloneDeep(window.__KBN__ || {});
export default deepFreeze(kbn);
export default deepFreeze(getState());

function deepFreeze(object) {
// for any properties that reference an object, makes sure that object is
Expand All @@ -20,3 +15,12 @@ function deepFreeze(object) {

return Object.freeze(object);
}

function getState() {
const stateKey = '__KBN__';
if (!(stateKey in window)) {
const state = $('kbn-initial-state').attr('data');
window[stateKey] = JSON.parse(state);
}
return window[stateKey];
}

0 comments on commit 41b0651

Please sign in to comment.