Comparing version 2.0.1 to 2.1.0
@@ -23,3 +23,3 @@ "use strict"; | ||
var events = ["added", "modified", "removed", "cleared"]; | ||
var events = ["added", "modified", "removed", "cleared", "ready"]; | ||
var EventName = _.object(events, events); | ||
@@ -60,2 +60,14 @@ | ||
function isInitialized() { | ||
return throwIfUninitialized !== throwUninitializedError; | ||
} | ||
function initialize() { | ||
var needsInitialization = !isInitialized(); | ||
if (needsInitialization) { | ||
throwIfUninitialized = _.noop; // Allow other methods to work without throwing. | ||
} | ||
return needsInitialization; | ||
} | ||
function addEvent(eventName) { | ||
@@ -211,3 +223,3 @@ if (!Storeit.EventName[eventName]) { | ||
that.clear = function () { | ||
throwIfUninitialized = _.noop; // Allow other methods to work without throwing. | ||
var publishReady = initialize(); // Initialize only if needed and return true if initalization was performed. | ||
getIndex().forEach(function (key) { // Remove everything from provider, loaded or not. | ||
@@ -222,2 +234,5 @@ storageProvider.removeItem(nskey(key)); | ||
publish(EventName.cleared); | ||
if (publishReady) { | ||
originalPublish(EventName.ready); | ||
} | ||
}; | ||
@@ -238,5 +253,3 @@ | ||
Object.defineProperty(that, "isInitialized", { | ||
get: function () { | ||
return throwIfUninitialized !== throwUninitializedError; | ||
}, | ||
get: isInitialized, | ||
enumerable: true | ||
@@ -258,2 +271,3 @@ }); | ||
}); | ||
originalPublish(EventName.ready); // Publish even if options.publish is false. | ||
}; | ||
@@ -260,0 +274,0 @@ |
{ | ||
"name": "storeit", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "A key/value storage system that publishes events.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/Storeit.js", |
Sorry, the diff of this file is not supported yet
42191
409