From cb7cb9583ab38bdc008883e3ed4c22fa6db1f3a5 Mon Sep 17 00:00:00 2001
From: liabru <liambrum@gmail.com>
Date: Tue, 29 Apr 2014 17:34:28 +0100
Subject: [PATCH] added Common.nextId, removed Body.nextId, removed
 Constraint.nextId, removed Composite.nextId

---
 src/body/Body.js             | 14 ++------------
 src/body/Composite.js        | 13 +------------
 src/constraint/Constraint.js | 14 ++------------
 src/core/Common.js           | 11 +++++++++++
 4 files changed, 16 insertions(+), 36 deletions(-)

diff --git a/src/body/Body.js b/src/body/Body.js
index 2a24b0f..6960437 100644
--- a/src/body/Body.js
+++ b/src/body/Body.js
@@ -9,8 +9,7 @@ var Body = {};
 
 (function() {
 
-    var _nextId = 0,
-        _nextGroupId = 1;
+    var _nextGroupId = 1;
 
     /**
      * Description to be written.
@@ -20,7 +19,7 @@ var Body = {};
      */
     Body.create = function(options) {
         var defaults = {
-            id: Body.nextId(),
+            id: Common.nextId(),
             type: 'body',
             label: 'Body',
             angle: 0,
@@ -62,15 +61,6 @@ var Body = {};
         return body;
     };
 
-    /**
-     * Description
-     * @method nextId
-     * @return {Number} Unique bodyID
-     */
-    Body.nextId = function() {
-        return _nextId++;
-    };
-    
     /**
      * Description
      * @method nextGroupId
diff --git a/src/body/Composite.js b/src/body/Composite.js
index b8e13d0..31f8001 100644
--- a/src/body/Composite.js
+++ b/src/body/Composite.js
@@ -11,8 +11,6 @@ var Composite = {};
 
 (function() {
 
-    var _nextId = 0;
-
     /**
      * Description
      * @method create
@@ -21,7 +19,7 @@ var Composite = {};
      */
     Composite.create = function(options) {
         return Common.extend({ 
-            id: Composite.nextId(),
+            id: Common.nextId(),
             type: 'composite',
             parent: null,
             isModified: false,
@@ -32,15 +30,6 @@ var Composite = {};
         }, options);
     };
 
-    /**
-     * Returns the next unique compositeID
-     * @method nextId
-     * @return {Number} Unique compositeID
-     */
-    Composite.nextId = function() {
-        return _nextId++;
-    };
-
     /**
      * Sets the composite's `isModified` flag. 
      * If `updateParents` is true, all parents will be set (default: false).
diff --git a/src/constraint/Constraint.js b/src/constraint/Constraint.js
index 1d71f38..f423634 100644
--- a/src/constraint/Constraint.js
+++ b/src/constraint/Constraint.js
@@ -18,8 +18,7 @@ var Constraint = {};
 (function() {
 
     var _minLength = 0.000001,
-        _minDifference = 0.001,
-        _nextId = 0;
+        _minDifference = 0.001;
 
     /**
      * Description
@@ -53,7 +52,7 @@ var Constraint = {};
         constraint.render = Common.extend(render, constraint.render);
 
         // option defaults
-        constraint.id = constraint.id || Constraint.nextId();
+        constraint.id = constraint.id || Common.nextId();
         constraint.label = constraint.label || 'Constraint';
         constraint.type = 'constraint';
         constraint.stiffness = constraint.stiffness || 1;
@@ -256,13 +255,4 @@ var Constraint = {};
         }
     };
 
-    /**
-     * Returns the next unique constraintId
-     * @method nextId
-     * @return {Number} Unique constraintId
-     */
-    Constraint.nextId = function() {
-        return _nextId++;
-    };
-
 })();
\ No newline at end of file
diff --git a/src/core/Common.js b/src/core/Common.js
index 61b8b2c..07d1248 100644
--- a/src/core/Common.js
+++ b/src/core/Common.js
@@ -8,6 +8,8 @@ var Common = {};
 
 (function() {
 
+    Common._nextId = 0;
+
     /**
      * Description
      * @method extend
@@ -267,4 +269,13 @@ var Common = {};
         console.log('%c [Matter] ' + type + ': ' + message, style);
     };
 
+    /**
+     * Returns the next unique sequential ID
+     * @method nextId
+     * @return {Number} Unique sequential ID
+     */
+    Common.nextId = function() {
+        return Common._nextId++;
+    };
+
 })();
\ No newline at end of file