Skip to content

Instantly share code, notes, and snippets.

@FlorianRappl
Created February 27, 2020 14:14
Show Gist options
  • Save FlorianRappl/6e3428b9e558fcb9478378b9ffaba17d to your computer and use it in GitHub Desktop.
Save FlorianRappl/6e3428b9e558fcb9478378b9ffaba17d to your computer and use it in GitHub Desktop.
const data = {};
window.getData = name => {
const item = data[name];
return item && item.value;
}
window.setData = (owner, name, value) => {
const previous = data[name];
if (!previous || previous.owner === owner) {
data[name] = {
owner,
name,
value,
};
window.dispatchEvent(new CustomEvent('changed-data', {
detail: {
name,
previous: previous && previous.value,
current: value,
},
}));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment