{"action":"closed","issue":{"url":"https://api.github.com/repos/Linkurious/linkurious.js/issues/249","repository_url":"https://api.github.com/repos/Linkurious/linkurious.js","labels_url":"https://api.github.com/repos/Linkurious/linkurious.js/issues/249/labels{/name}","comments_url":"https://api.github.com/repos/Linkurious/linkurious.js/issues/249/comments","events_url":"https://api.github.com/repos/Linkurious/linkurious.js/issues/249/events","html_url":"https://github.com/Linkurious/linkurious.js/issues/249","id":100760840,"number":249,"title":"Guard node coordinates values against bad values","user":{"login":"mdamien","id":1469823,"avatar_url":"https://avatars.githubusercontent.com/u/1469823?v=3","gravatar_id":"","url":"https://api.github.com/users/mdamien","html_url":"https://github.com/mdamien","followers_url":"https://api.github.com/users/mdamien/followers","following_url":"https://api.github.com/users/mdamien/following{/other_user}","gists_url":"https://api.github.com/users/mdamien/gists{/gist_id}","starred_url":"https://api.github.com/users/mdamien/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdamien/subscriptions","organizations_url":"https://api.github.com/users/mdamien/orgs","repos_url":"https://api.github.com/users/mdamien/repos","events_url":"https://api.github.com/users/mdamien/events{/privacy}","received_events_url":"https://api.github.com/users/mdamien/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Linkurious/linkurious.js/labels/status:need-specs","name":"status:need-specs","color":"d7191c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-13T12:47:02Z","updated_at":"2016-05-19T12:47:17Z","closed_at":"2016-05-19T12:47:17Z","body":"The idea is simple: Sometimes, the value of `node.x` or `node.y` can be set to bad values (null, undefined, string, object,...), we can make this impossible by throwing an error when the user try to do that:\r\n\r\n```javascript\r\n    var guard = function(prop) {\r\n      var val = node[prop],\r\n        getter = function() { return val; },\r\n        setter = function(newval) {\r\n          if (!newval) {\r\n            throw new Error('Incorrect val for node.'+prop+': '+newval);\r\n          }\r\n          val = newval;\r\n          return newval;\r\n        };\r\n          \r\n      Object.defineProperty(validNode, prop, {\r\n        get: getter,\r\n        set: setter,\r\n        enumerable: true,\r\n        configurable: true,\r\n      });\r\n    };\r\n\r\n    guard('x');\r\n    guard('y');\r\n```\r\n\r\nThen, life will be easier and there will be many more rainbows in the world thanks to this :)\r\n\r\nThis can only be included after a good performance impact analysis but it looks like it doesn't influence performance."}}