Skip to content

Commit

Permalink
fix: Protect the model against mutations.
Browse files Browse the repository at this point in the history
The model is exposed as the items are often part of the notification. This commit make sure it cannot be altered in any way.
  • Loading branch information
QuentinRoy committed Aug 1, 2017
1 parent 8529971 commit c988723
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,14 @@ const recursivelyCreateModelItems = (items, baseId = undefined) => {
i * angleRange
];
if (item.children) {
return new MenuItem(
...itemArgs,
recursivelyCreateModelItems(item.children, stdId)
return Object.freeze(
new MenuItem(
...itemArgs,
Object.freeze(recursivelyCreateModelItems(item.children, stdId))
)
);
}
return new Item(...itemArgs);
return Object.freeze(new Item(...itemArgs));
});
};

Expand All @@ -135,6 +137,8 @@ const recursivelyCreateModelItems = (items, baseId = undefined) => {
* @return {MenuItem} - The root item of the model.
*/
const createModel = itemList =>
new MenuItem(null, null, null, recursivelyCreateModelItems(itemList));
Object.freeze(
new MenuItem(null, null, null, recursivelyCreateModelItems(itemList))
);

export default createModel;

0 comments on commit c988723

Please sign in to comment.