GitHub PullRequestReviewCommentEvent at 2014-04-03 18:03:15
Repository: brackets
Actor: RaymondLim
Payload: {"comment":{"url":"https://api.github.com/repos/adobe/brackets/pulls/comments/11264183","id":11264183,"diff_hunk":"@@ -0,0 +1,112 @@\n+/*\n+ * Copyright (c) 2013 Adobe Systems Incorporated.\n+ *\n+ * Permission is hereby granted, free of charge, to any person obtaining a\n+ * copy of this software and associated documentation files (the \"Software\"),\n+ * to deal in the Software without restriction, including without limitation\n+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n+ * and/or sell copies of the Software, and to permit persons to whom the\n+ * Software is furnished to do so, subject to the following conditions:\n+ *\n+ * The above copyright notice and this permission notice shall be included in\n+ * all copies or substantial portions of the Software.\n+ *\n+ * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n+ * DEALINGS IN THE SOFTWARE.\n+ */\n+\n+/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */\n+/*global define, $, brackets */\n+\n+define(function (require, exports, module) {\n+    \"use strict\";\n+\n+    var _ = brackets.getModule(\"thirdparty/lodash\");\n+\n+    /**\n+      @constructor\n+      Lightweight model to set and get data from.\n+\n+      Dispatches events on change and reset, if not explicitly asked to be silent:\n+        change -- when the properties in the model are changed with the setter.\n+\n+      @param {Object=} properties Object literal with key/values to store as default; optional\n+    */\n+    function Model(properties) {\n+\n+        if (!(this instanceof Model)) {\n+            return new Model(properties);\n+        }\n+\n+        var _initial = properties || {},\n+            _props = {},\n+            _events = {};\n+\n+        /**\n+          Sets or updates properties on the model.\n+\n+          @throws {TypeError} if input is falsy or not object\n+          @param {!Object} obj Object literal with key/value pairs\n+          @param {boolean=} silent set to false to avoid triggering \"change\" event\n+        */\n+        var _set = function (obj, silent) {\n+            var hasChanged = false,\n+                k;\n+\n+            if (!obj || typeof obj !== \"object\") {\n+                throw new TypeError(\"Invalid input. Expected object with properties, got: \" + obj);\n+            }\n+\n+            for (k in obj) {\n+                if (obj.hasOwnProperty(k)) {\n+                    if (!_.isEqual(_props[k], obj[k])) {\n+                        _props[k] = obj[k];\n+                        hasChanged = true;\n+                    }\n+                }\n+            }\n+\n+            if (silent !== true && hasChanged) {\n+                $(this).triggerHandler(\"change\", [_props]);\n+            }\n+        };\n+\n+        if (typeof properties === \"object\") {\n+            _set(properties, true);\n+        }\n+\n+        return {\n+            set: _set,\n+\n+            /**\n+              Get a property value from the model\n+              @param {!string} key\n+              @return {undefined|*}\n+            */\n+            get: function (key) {\n+                return _props[key];\n+            },\n+\n+            /**\n+              Reset the model to its initial contents\n+              @param {boolean=} silent; if true, will not trigger \"change\" event\n+            */\n+            reset: function (silent) {\n+\n+                // assign a clone of the initial properties\n+                _props = JSON.parse(JSON.stringify(_initial));","path":"src/extensions/default/CSSShapesEditor/Model.js","position":102,"original_position":102,"commit_id":"11c684d79061cc898a1f456f16ed640d7daa08ff","original_commit_id":"11c684d79061cc898a1f456f16ed640d7daa08ff","user":{"login":"RaymondLim","id":1542488,"avatar_url":"https://avatars.githubusercontent.com/u/1542488?","gravatar_id":"5e78f1f6398b643b4e5269d2ab5e24c6","url":"https://api.github.com/users/RaymondLim","html_url":"https://github.com/RaymondLim","followers_url":"https://api.github.com/users/RaymondLim/followers","following_url":"https://api.github.com/users/RaymondLim/following{/other_user}","gists_url":"https://api.github.com/users/RaymondLim/gists{/gist_id}","starred_url":"https://api.github.com/users/RaymondLim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RaymondLim/subscriptions","organizations_url":"https://api.github.com/users/RaymondLim/orgs","repos_url":"https://api.github.com/users/RaymondLim/repos","events_url":"https://api.github.com/users/RaymondLim/events{/privacy}","received_events_url":"https://api.github.com/users/RaymondLim/received_events","type":"User","site_admin":false},"body":"I'm fine to use this approach. Just FYI, if you have any functions in your object `stringify` may remove all of them.","created_at":"2014-04-03T18:03:15Z","updated_at":"2014-04-03T18:03:15Z","html_url":"https://github.com/adobe/brackets/pull/7384#discussion_r11264183","pull_request_url":"https://api.github.com/repos/adobe/brackets/pulls/7384","_links":{"self":{"href":"https://api.github.com/repos/adobe/brackets/pulls/comments/11264183"},"html":{"href":"https://github.com/adobe/brackets/pull/7384#discussion_r11264183"},"pull_request":{"href":"https://api.github.com/repos/adobe/brackets/pulls/7384"}}}}