├── test ├── Blazor.Extensions.Storage.Test │ ├── Pages │ │ ├── _Imports.razor │ │ └── Index.razor │ ├── Shared │ │ └── MainLayout.razor │ ├── _Imports.razor │ ├── Program.cs │ ├── App.razor │ ├── wwwroot │ │ ├── index.html │ │ └── weather.json │ ├── Startup.cs │ ├── Blazor.Extensions.Storage.Test.csproj │ └── Interop │ │ └── InteropStorage.cs └── Directory.Build.props ├── src ├── Blazor.Extensions.Storage │ ├── Interfaces │ │ ├── ILocalStorage.cs │ │ ├── ISessionStorage.cs │ │ └── IStorage.cs │ ├── Constants.cs │ ├── LocalStorage.cs │ ├── SessionStorage.cs │ ├── StorageExtensions.cs │ ├── Blazor.Extensions.Storage.csproj │ └── Storage.cs ├── Blazor.Extensions.Storage.JS │ ├── tslint.json │ ├── tsconfig.json │ ├── package.json │ ├── webpack.config.js │ ├── tsfmt.json │ ├── src │ │ ├── InitializeStorage.ts │ │ └── BrowserStorage.ts │ ├── Blazor.Extensions.Storage.JS.csproj │ └── package-lock.json ├── Directory.Build.targets └── Directory.Build.props ├── Directory.Build.targets ├── .github └── workflows │ ├── ci.yml │ └── publish.yml ├── LICENSE ├── README.md ├── Directory.Build.props ├── Storage.sln ├── .gitignore └── .editorconfig /test/Blazor.Extensions.Storage.Test/Pages/_Imports.razor: -------------------------------------------------------------------------------- 1 | @layout MainLayout 2 | -------------------------------------------------------------------------------- /test/Blazor.Extensions.Storage.Test/Shared/MainLayout.razor: -------------------------------------------------------------------------------- 1 | @inherits LayoutComponentBase 2 | 3 |
4 | @Body 5 |
6 | -------------------------------------------------------------------------------- /src/Blazor.Extensions.Storage/Interfaces/ILocalStorage.cs: -------------------------------------------------------------------------------- 1 | namespace Blazor.Extensions.Storage.Interfaces 2 | { 3 | public interface ILocalStorage : IStorage {} 4 | } 5 | -------------------------------------------------------------------------------- /src/Blazor.Extensions.Storage/Interfaces/ISessionStorage.cs: -------------------------------------------------------------------------------- 1 | namespace Blazor.Extensions.Storage.Interfaces 2 | { 3 | public interface ISessionStorage : IStorage {} 4 | } 5 | -------------------------------------------------------------------------------- /src/Blazor.Extensions.Storage/Constants.cs: -------------------------------------------------------------------------------- 1 | namespace Blazor.Extensions 2 | { 3 | internal class StorageTypeNames 4 | { 5 | public const string SESSION_STORAGE = "sessionStorage"; 6 | public const string LOCAL_STORAGE = "localStorage"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Directory.Build.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(Version). Commit Hash: $(GitHeadSha) 5 | 6 | 7 | -------------------------------------------------------------------------------- /test/Blazor.Extensions.Storage.Test/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using System.Net.Http 2 | @using Microsoft.AspNetCore.Components.Routing 3 | @using Microsoft.JSInterop 4 | @using Blazor.Extensions.Storage 5 | @using Blazor.Extensions.Storage.Test 6 | @using Blazor.Extensions.Storage.Test.Shared 7 | -------------------------------------------------------------------------------- /src/Blazor.Extensions.Storage/LocalStorage.cs: -------------------------------------------------------------------------------- 1 | using Blazor.Extensions.Storage.Interfaces; 2 | using Microsoft.JSInterop; 3 | 4 | namespace Blazor.Extensions.Storage 5 | { 6 | internal class LocalStorage : Storage, ILocalStorage 7 | { 8 | public LocalStorage(IJSRuntime runtime) : base(runtime, StorageTypeNames.LOCAL_STORAGE) {} 9 | } 10 | } -------------------------------------------------------------------------------- /src/Blazor.Extensions.Storage/SessionStorage.cs: -------------------------------------------------------------------------------- 1 | using Blazor.Extensions.Storage.Interfaces; 2 | using Microsoft.JSInterop; 3 | 4 | namespace Blazor.Extensions.Storage 5 | { 6 | internal class SessionStorage : Storage, ISessionStorage 7 | { 8 | public SessionStorage(IJSRuntime runtime) : base(runtime, StorageTypeNames.SESSION_STORAGE) {} 9 | } 10 | } -------------------------------------------------------------------------------- /src/Blazor.Extensions.Storage.JS/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "no-string-throw": true, 4 | "no-unused-expression": true, 5 | "no-duplicate-variable": true, 6 | "curly": true, 7 | "class-name": true, 8 | "semicolon": [ 9 | true, 10 | "always" 11 | ], 12 | "triple-equals": true 13 | }, 14 | "defaultSeverity": "warning" 15 | } 16 | -------------------------------------------------------------------------------- /src/Blazor.Extensions.Storage.JS/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "noImplicitAny": false, 4 | "noEmitOnError": true, 5 | "removeComments": true, 6 | "sourceMap": true, 7 | "target": "es6", 8 | "module": "commonjs", 9 | "lib": ["es2016", "dom"], 10 | "strict": true, 11 | "alwaysStrict": true, 12 | "preserveConstEnums": true 13 | }, 14 | "exclude": [ 15 | "node_modules" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v1 15 | - name: Setup .NET Core 16 | uses: actions/setup-dotnet@v1 17 | with: 18 | dotnet-version: 3.1.100-preview3-014645 19 | - name: Build 20 | run: dotnet build --configuration Release -------------------------------------------------------------------------------- /src/Blazor.Extensions.Storage/Interfaces/IStorage.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace Blazor.Extensions.Storage.Interfaces 4 | { 5 | public interface IStorage 6 | { 7 | ValueTask GetItem(string key); 8 | ValueTask Key(int index); 9 | ValueTask RemoveItem(string key); 10 | ValueTask SetItem(string key, TItem item); 11 | ValueTask Clear(); 12 | ValueTask Length(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Blazor.Extensions.Storage.JS/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "blazor.extensions.storage", 3 | "version": "0.0.1", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "webpack-cli", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "devDependencies": { 11 | "@types/emscripten": "0.0.31", 12 | "ts-loader": "^4.4.2", 13 | "typescript": "^2.9.2", 14 | "webpack": "^4.16.3", 15 | "webpack-cli": "^3.1.0" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/Blazor.Extensions.Storage.Test/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Blazor.Hosting; 2 | 3 | namespace Blazor.Extensions.Storage.Test 4 | { 5 | public class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | CreateHostBuilder(args).Build().Run(); 10 | } 11 | 12 | public static IWebAssemblyHostBuilder CreateHostBuilder(string[] args) => 13 | BlazorWebAssemblyHost.CreateDefaultBuilder() 14 | .UseBlazorStartup(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Blazor.Extensions.Storage/StorageExtensions.cs: -------------------------------------------------------------------------------- 1 | using Blazor.Extensions.Storage.Interfaces; 2 | using Microsoft.Extensions.DependencyInjection; 3 | 4 | namespace Blazor.Extensions.Storage 5 | { 6 | public static class StorageExtensions 7 | { 8 | public static IServiceCollection AddStorage(this IServiceCollection services) 9 | { 10 | return services.AddScoped() 11 | .AddScoped(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/Blazor.Extensions.Storage.Test/App.razor: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 |

Page not found

11 |

Sorry, but there's nothing here!

12 |
13 |
14 | -------------------------------------------------------------------------------- /src/Blazor.Extensions.Storage.JS/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | const webpack = require("webpack"); 3 | 4 | module.exports = { 5 | mode: 'production', 6 | resolve: { 7 | extensions: [".ts", ".js"] 8 | }, 9 | devtool: "inline-source-map", 10 | module: { 11 | rules: [ 12 | { 13 | test: /\.ts?$/, 14 | loader: "ts-loader" 15 | } 16 | ] 17 | }, 18 | entry: { 19 | "blazor.extensions.storage": "./src/InitializeStorage.ts" 20 | }, 21 | output: { 22 | path: path.join(__dirname, "/dist"), 23 | filename: "[name].js" 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /src/Directory.Build.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | <_ParentDirectoryBuildTargetsPath Condition="'$(_DirectoryBuildPropsFile)' != ''">$([System.IO.Path]::Combine('..', '$(_DirectoryBuildTargetsFile)')) 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/Blazor.Extensions.Storage.Test/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Blazor.Extensions.Storage.Test 7 | 8 | 9 | 10 | Loading... 11 | 12 | 13 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /test/Blazor.Extensions.Storage.Test/Startup.cs: -------------------------------------------------------------------------------- 1 | using Blazor.Extensions.Storage.Test.Interop; 2 | using Microsoft.AspNetCore.Components.Builder; 3 | using Microsoft.Extensions.DependencyInjection; 4 | 5 | namespace Blazor.Extensions.Storage.Test 6 | { 7 | public class Startup 8 | { 9 | public void ConfigureServices(IServiceCollection services) 10 | { 11 | //Add Blazor.Extensions.Storage 12 | services.AddStorage(); 13 | 14 | services.AddScoped(); 15 | } 16 | 17 | public void Configure(IComponentsApplicationBuilder app) 18 | { 19 | app.AddComponent("app"); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/Blazor.Extensions.Storage.Test/wwwroot/weather.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "Date": "2018-05-06", 4 | "TemperatureC": 1, 5 | "Summary": "Freezing", 6 | "TemperatureF": 33 7 | }, 8 | { 9 | "Date": "2018-05-07", 10 | "TemperatureC": 14, 11 | "Summary": "Bracing", 12 | "TemperatureF": 57 13 | }, 14 | { 15 | "Date": "2018-05-08", 16 | "TemperatureC": -13, 17 | "Summary": "Freezing", 18 | "TemperatureF": 9 19 | }, 20 | { 21 | "Date": "2018-05-09", 22 | "TemperatureC": -16, 23 | "Summary": "Balmy", 24 | "TemperatureF": 4 25 | }, 26 | { 27 | "Date": "2018-05-10", 28 | "TemperatureC": -2, 29 | "Summary": "Chilly", 30 | "TemperatureF": 29 31 | } 32 | ] 33 | -------------------------------------------------------------------------------- /src/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | <_ParentDirectoryBuildPropsPath Condition="'$(_DirectoryBuildPropsFile)' != ''">$([System.IO.Path]::Combine('..', '$(_DirectoryBuildPropsFile)')) 4 | 5 | 6 | 7 | 8 | 9 | true 10 | 11 | 12 | 13 | 14 | true 15 | https://github.com/BlazorExtensions/Storage 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/Blazor.Extensions.Storage.JS/tsfmt.json: -------------------------------------------------------------------------------- 1 | { 2 | "tabSize": 2, 3 | "indentSize": 2, 4 | "convertTabsToSpaces": true, 5 | "insertSpaceAfterCommaDelimiter": true, 6 | "insertSpaceAfterSemicolonInForStatements": true, 7 | "insertSpaceBeforeAndAfterBinaryOperators": true, 8 | "insertSpaceAfterKeywordsInControlFlowStatements": true, 9 | "insertSpaceAfterFunctionKeywordForAnonymousFunctions": true, 10 | "insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false, 11 | "insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, 12 | "insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false, 13 | "insertSpaceBeforeFunctionParenthesis": false, 14 | "placeOpenBraceOnNewLineForFunctions": false, 15 | "placeOpenBraceOnNewLineForControlBlocks": false 16 | } 17 | -------------------------------------------------------------------------------- /src/Blazor.Extensions.Storage.JS/src/InitializeStorage.ts: -------------------------------------------------------------------------------- 1 | import { BrowserStorage } from './BrowserStorage'; 2 | 3 | namespace Storage { 4 | const blazorExtensions: string = 'BlazorExtensions'; 5 | // define what this extension adds to the window object inside BlazorExtensions 6 | const extensionObject = { 7 | Storage: new BrowserStorage() 8 | }; 9 | 10 | export function initialize(): void { 11 | if (typeof window !== 'undefined' && !window[blazorExtensions]) { 12 | // when the library is loaded in a browser via a