mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
restructured the id generation...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
6b86b7c7b5
commit
9dde5d0326
@ -338,6 +338,36 @@ var BaseBrowserPrototype = {
|
|||||||
__list__: function(make, options){
|
__list__: function(make, options){
|
||||||
throw new Error('.__list__(..): Not implemented.') },
|
throw new Error('.__list__(..): Not implemented.') },
|
||||||
|
|
||||||
|
// Key getter/generator...
|
||||||
|
//
|
||||||
|
// XXX should these include the path???
|
||||||
|
// XXX is JSON the best key format???
|
||||||
|
__key__: function(item){
|
||||||
|
return item.id
|
||||||
|
// value is a browser -> generate an unique id...
|
||||||
|
// XXX identify via structure...
|
||||||
|
|| (item.value instanceof Browser
|
||||||
|
&& this.__id__())
|
||||||
|
|| JSON.stringify(item.value) },
|
||||||
|
|
||||||
|
// ID generator...
|
||||||
|
//
|
||||||
|
// Format:
|
||||||
|
// "<date>"
|
||||||
|
// "<prefix> <date>"
|
||||||
|
//
|
||||||
|
// XXX do a better id...
|
||||||
|
// XXX not sure about the logic of this, should this take an item as
|
||||||
|
// input and return an id???
|
||||||
|
// ...should this check for uniqueness???
|
||||||
|
__id__: function(prefix){
|
||||||
|
// id prefix...
|
||||||
|
return (prefix || '')
|
||||||
|
// separator...
|
||||||
|
+ (prefix ? ' ' : '')
|
||||||
|
// date...
|
||||||
|
+ Date.now() },
|
||||||
|
|
||||||
|
|
||||||
// Make .items...
|
// Make .items...
|
||||||
//
|
//
|
||||||
@ -365,16 +395,6 @@ var BaseBrowserPrototype = {
|
|||||||
var old_index = this.item_index || {}
|
var old_index = this.item_index || {}
|
||||||
var new_index = this.item_index = {}
|
var new_index = this.item_index = {}
|
||||||
|
|
||||||
// XXX do a better id...
|
|
||||||
// XXX should this be a method???
|
|
||||||
var makeID = function(id){
|
|
||||||
// id prefix...
|
|
||||||
return (id || '')
|
|
||||||
// separator...
|
|
||||||
+ (id && ' ')
|
|
||||||
// date...
|
|
||||||
+ Date.now() }
|
|
||||||
|
|
||||||
// item constructor...
|
// item constructor...
|
||||||
//
|
//
|
||||||
// make(value[, options])
|
// make(value[, options])
|
||||||
@ -397,15 +417,13 @@ var BaseBrowserPrototype = {
|
|||||||
args.pop(),
|
args.pop(),
|
||||||
opts)
|
opts)
|
||||||
: opts
|
: opts
|
||||||
|
opts = Object.assign(
|
||||||
|
{},
|
||||||
|
opts,
|
||||||
|
{value: value})
|
||||||
|
|
||||||
// item id...
|
// item id...
|
||||||
// XXX should these include the path???
|
var key = this.__key__(opts)
|
||||||
var key = opts.id
|
|
||||||
// value is a browser -> generate an unique id...
|
|
||||||
// XXX identify via structure...
|
|
||||||
|| (value instanceof Browser
|
|
||||||
&& makeID())
|
|
||||||
|| JSON.stringify(value)
|
|
||||||
var id_changed = (old_index[key] || {}).id_changed
|
var id_changed = (old_index[key] || {}).id_changed
|
||||||
|
|
||||||
// handle duplicate ids -> err if found...
|
// handle duplicate ids -> err if found...
|
||||||
@ -436,7 +454,7 @@ var BaseBrowserPrototype = {
|
|||||||
new_index[key].id_changed = true
|
new_index[key].id_changed = true
|
||||||
|
|
||||||
// create a new key...
|
// create a new key...
|
||||||
k = makeID(key)
|
k = this.__id__(key)
|
||||||
}
|
}
|
||||||
key = opts.id = k
|
key = opts.id = k
|
||||||
|
|
||||||
@ -448,8 +466,7 @@ var BaseBrowserPrototype = {
|
|||||||
: old_index[key] || {},
|
: old_index[key] || {},
|
||||||
// XXX ???
|
// XXX ???
|
||||||
options || {},
|
options || {},
|
||||||
opts,
|
opts)
|
||||||
{value: value})
|
|
||||||
|
|
||||||
// store the item...
|
// store the item...
|
||||||
items.push(item)
|
items.push(item)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user