From f9e8a00081a0f62854881bfa8f504aa5e4fded91 Mon Sep 17 00:00:00 2001 From: rodrigopavezi Date: Thu, 27 Jul 2017 15:36:21 -0300 Subject: [PATCH 1/3] Implemented ability to tell which storage, local or session to be used --- bower.json | 2 +- package.json | 8 +- rise-data.html | 73 ++++++++--- test/unit/rise-data-cache.html | 2 +- .../rise-data-local-storage-rc-running.html | 2 +- test/unit/rise-data-local-storage.html | 2 +- .../rise-data-none-storage-rc-running.html | 106 +++++++++++++++ .../rise-data-session-storage-rc-running.html | 99 ++++++++++++++ test/unit/rise-data-session-storage.html | 123 ++++++++++++++++++ test/unit/rise-data.html | 2 +- 10 files changed, 395 insertions(+), 24 deletions(-) create mode 100644 test/unit/rise-data-none-storage-rc-running.html create mode 100644 test/unit/rise-data-session-storage-rc-running.html create mode 100644 test/unit/rise-data-session-storage.html diff --git a/bower.json b/bower.json index 6ac37df..42d8cf7 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "rise-data", - "version": "1.3.7", + "version": "1.3.8", "authors": [ "Rise Vision" ], diff --git a/package.json b/package.json index 5f3c07e..b207cd1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rise-data", - "version": "1.3.7", + "version": "1.3.8", "description": "Web component for storing data", "scripts": { "test": "gulp test", @@ -28,7 +28,7 @@ "devDependencies": { "colors": "~1.1.0", "del": "~1.1.1", - "eslint": "^3.8.1", + "eslint": "^3.19.0", "eslint-config-idiomatic": "^2.1.0", "eslint-plugin-html": "^1.6.0", "gulp": "~3.8.10", @@ -37,7 +37,7 @@ "gulp-eslint": "^3.0.1", "gulp-html-replace": "~1.6.1", "run-sequence": "~1.1.0", - "web-component-tester": "*", - "widget-tester": "git://github.com/Rise-Vision/widget-tester.git" + "web-component-tester": "^6.0.0", + "widget-tester": "git://github.com/Rise-Vision/widget-tester.git#feature/session-storage-mock" } } diff --git a/rise-data.html b/rise-data.html index c367151..c953ff1 100644 --- a/rise-data.html +++ b/rise-data.html @@ -32,7 +32,7 @@ - + diff --git a/test/unit/rise-data-local-storage-rc-running.html b/test/unit/rise-data-local-storage-rc-running.html index f5e55bb..26032e7 100644 --- a/test/unit/rise-data-local-storage-rc-running.html +++ b/test/unit/rise-data-local-storage-rc-running.html @@ -12,7 +12,7 @@ - + diff --git a/test/unit/rise-data-local-storage.html b/test/unit/rise-data-local-storage.html index 72a489e..39b9c0a 100644 --- a/test/unit/rise-data-local-storage.html +++ b/test/unit/rise-data-local-storage.html @@ -12,7 +12,7 @@ - + diff --git a/test/unit/rise-data-none-storage-rc-running.html b/test/unit/rise-data-none-storage-rc-running.html new file mode 100644 index 0000000..53ef809 --- /dev/null +++ b/test/unit/rise-data-none-storage-rc-running.html @@ -0,0 +1,106 @@ + + + + + + rise-data + + + + + + + + + + + + + + + + + diff --git a/test/unit/rise-data-session-storage-rc-running.html b/test/unit/rise-data-session-storage-rc-running.html new file mode 100644 index 0000000..bae2d50 --- /dev/null +++ b/test/unit/rise-data-session-storage-rc-running.html @@ -0,0 +1,99 @@ + + + + + + rise-data + + + + + + + + + + + + + + + + diff --git a/test/unit/rise-data-session-storage.html b/test/unit/rise-data-session-storage.html new file mode 100644 index 0000000..daff227 --- /dev/null +++ b/test/unit/rise-data-session-storage.html @@ -0,0 +1,123 @@ + + + + + + rise-data + + + + + + + + + + + + + + + + diff --git a/test/unit/rise-data.html b/test/unit/rise-data.html index e59d094..e88cb36 100644 --- a/test/unit/rise-data.html +++ b/test/unit/rise-data.html @@ -12,7 +12,7 @@ - + From b7b26ce836c92e04a6a703161b8701a1b1b51781 Mon Sep 17 00:00:00 2001 From: rodrigopavezi Date: Thu, 27 Jul 2017 15:40:08 -0300 Subject: [PATCH 2/3] Updated web-testers --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b207cd1..35f8e53 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,6 @@ "gulp-html-replace": "~1.6.1", "run-sequence": "~1.1.0", "web-component-tester": "^6.0.0", - "widget-tester": "git://github.com/Rise-Vision/widget-tester.git#feature/session-storage-mock" + "widget-tester": "git://github.com/Rise-Vision/widget-tester.git" } } From c818600264d75a888e52894b4c38c95af1052b3b Mon Sep 17 00:00:00 2001 From: rodrigopavezi Date: Thu, 27 Jul 2017 16:20:27 -0300 Subject: [PATCH 3/3] removed support checks --- rise-data.html | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/rise-data.html b/rise-data.html index c953ff1..34425ae 100644 --- a/rise-data.html +++ b/rise-data.html @@ -43,22 +43,6 @@ var BQ_TABLE_NAME = "component_data_events"; - function supportsLocalStorage() { - try { - return "localStorage" in window && window.localStorage !== null; - } catch ( e ) { - return false; - } - } - - function supportsSessionStorage() { - try { - return "sessionStorage" in window && window.sessionStorage !== null; - } catch ( e ) { - return false; - } - } - Polymer( { is: "rise-data", @@ -157,13 +141,13 @@ _getCachedDataFromStorage: function( key, cb ) { var data = null; - if ( this._isLocalStorage() && supportsLocalStorage() ) { + if ( this._isLocalStorage() ) { try { data = JSON.parse( localStorage.getItem( key ), this._dateReviver ); } catch ( e ) { console.warn( e ); // eslint-disable-line no-console } - } else if ( this._isSessionStorage() && supportsSessionStorage() ) { + } else if ( this._isSessionStorage() ) { try { data = JSON.parse( sessionStorage.getItem( key ), this._dateReviver ); } catch ( e ) { @@ -420,13 +404,13 @@ this._save( key, data ); } } - if ( this._isLocalStorage() && supportsLocalStorage() ) { + if ( this._isLocalStorage() ) { try { localStorage.setItem( key, JSON.stringify( data ) ); } catch ( e ) { console.warn( e ); // eslint-disable-line no-console } - } else if ( this._isSessionStorage() && supportsSessionStorage() ) { + } else if ( this._isSessionStorage() ) { try { sessionStorage.setItem( key, JSON.stringify( data ) ); } catch ( e ) { @@ -491,13 +475,13 @@ } } - if ( this._isLocalStorage() && supportsLocalStorage() ) { + if ( this._isLocalStorage() ) { try { localStorage.removeItem( key ); } catch ( ex ) { console.warn( ex ); // eslint-disable-line no-console } - } else if ( this._isSessionStorage() && supportsSessionStorage() ) { + } else if ( this._isSessionStorage() ) { try { sessionStorage.removeItem( key ); } catch ( ex ) {