diff options
| author | LV-426 <lv-426@taproot.org.il> | 2014-11-19 03:20:36 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-11-19 23:23:40 +0200 |
| commit | d93874113319d07ed36200da85888a92a4257e22 (patch) | |
| tree | 22eef2a5cd244b09bad5cb403881069ce61bb458 /src/model/core.js | |
| parent | 0027ec34a90f1d22523c16ffa533a1c3b052c358 (diff) | |
add rz_config, provide id generation scheme control: hash/seq, defaulting to seq
Diffstat (limited to 'src/model/core.js')
| -rw-r--r-- | src/model/core.js | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/model/core.js b/src/model/core.js index 6111954b..aff222f6 100644 --- a/src/model/core.js +++ b/src/model/core.js @@ -8,12 +8,33 @@ define([], function() { /** * return a random id */ - var random_id = function() { - return Math.random().toString(36).substring(2); + var random_id; + + var random_id__hash = function() { + return Math.random().toString(36).substring(2, 10); + } + + var random_id__seq = function () { + var id = 0; + function get_next() { + var next = id; + id += 1; + return next; + } + return get_next; } function random_node_name() { - return Math.random().toString(36).substring(2, 10); + return random_id__hash(); + } + + function init(config){ + if (config['rand_id_generator'] == 'hash') { + random_id = random_id__hash; + } + if (config['rand_id_generator'] == 'seq') { + random_id = random_id__seq(); + } } function Node() { @@ -144,6 +165,7 @@ define([], function() { } return { + init : init, random_node_name : random_node_name, crete_node_from_spec : crete_node_from_spec, crete_link_from_spec : crete_link_from_spec, |
