-
-
Notifications
You must be signed in to change notification settings - Fork 121
feat: mmkv #328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
feat: mmkv #328
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8130997
feat: add mmkv
triniwiz 60241c1
feat: mmkv metal & localStorage shim
triniwiz f465bd1
Merge branch 'main' into feat/mmkv
triniwiz a310020
Merge branch 'main' into feat/mmkv
NathanWalker 2e144a3
Merge remote-tracking branch 'origin/main' into feat/mmkv
NathanWalker d44f8b0
fix: initialization
NathanWalker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
.gitmodules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "packages/mmkv-metal/src-native/android/MMKV"] | ||
path = packages/mmkv-metal/src-native/android/MMKV | ||
url = https://github.com/Tencent/MMKV.git |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
apps/demo-angular/src/plugin-demos/mmkv-metal.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<ActionBar title="mmkv-metal" class="action-bar"> </ActionBar> | ||
<StackLayout class="p-20"> | ||
<ScrollView class="h-full"> | ||
<StackLayout> | ||
<Button text="Test mmkv-metal" (tap)="demoShared.testIt()" class="btn btn-primary"></Button> | ||
</StackLayout> | ||
</ScrollView> | ||
</StackLayout> |
17 changes: 17 additions & 0 deletions
apps/demo-angular/src/plugin-demos/mmkv-metal.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Component, NgZone } from '@angular/core'; | ||
import { DemoSharedMmkvMetal } from '@demo/shared'; | ||
import {} from '@nativescript/mmkv-metal'; | ||
|
||
@Component({ | ||
selector: 'demo-mmkv-metal', | ||
templateUrl: 'mmkv-metal.component.html', | ||
}) | ||
export class MmkvMetalComponent { | ||
demoShared: DemoSharedMmkvMetal; | ||
|
||
constructor(private _ngZone: NgZone) {} | ||
|
||
ngOnInit() { | ||
this.demoShared = new DemoSharedMmkvMetal(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
apps/demo-angular/src/plugin-demos/mmkv-metal.module.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core'; | ||
import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular'; | ||
import { MmkvMetalComponent } from './mmkv-metal.component'; | ||
|
||
@NgModule({ | ||
imports: [NativeScriptCommonModule, NativeScriptRouterModule.forChild([{ path: '', component: MmkvMetalComponent }])], | ||
declarations: [MmkvMetalComponent], | ||
schemas: [NO_ERRORS_SCHEMA], | ||
}) | ||
export class MmkvMetalModule {} |
8 changes: 8 additions & 0 deletions
apps/demo-angular/src/plugin-demos/mmkv.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<ActionBar title="mmkv" class="action-bar"> </ActionBar> | ||
<StackLayout class="p-20"> | ||
<ScrollView class="h-full"> | ||
<StackLayout> | ||
<Button text="Test mmkv" (tap)="demoShared.testIt()" class="btn btn-primary"></Button> | ||
</StackLayout> | ||
</ScrollView> | ||
</StackLayout> |
17 changes: 17 additions & 0 deletions
apps/demo-angular/src/plugin-demos/mmkv.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Component, NgZone } from '@angular/core'; | ||
import { DemoSharedMmkv } from '@demo/shared'; | ||
import {} from '@nativescript/mmkv'; | ||
|
||
@Component({ | ||
selector: 'demo-mmkv', | ||
templateUrl: 'mmkv.component.html', | ||
}) | ||
export class MmkvComponent { | ||
demoShared: DemoSharedMmkv; | ||
|
||
constructor(private _ngZone: NgZone) {} | ||
|
||
ngOnInit() { | ||
this.demoShared = new DemoSharedMmkv(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
apps/demo-angular/src/plugin-demos/mmkv.module.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core'; | ||
import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular'; | ||
import { MmkvComponent } from './mmkv.component'; | ||
|
||
@NgModule({ | ||
imports: [NativeScriptCommonModule, NativeScriptRouterModule.forChild([{ path: '', component: MmkvComponent }])], | ||
declarations: [MmkvComponent], | ||
schemas: [NO_ERRORS_SCHEMA], | ||
}) | ||
export class MmkvModule {} |
12 changes: 6 additions & 6 deletions
apps/demo/nativescript.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
import { NativeScriptConfig } from '@nativescript/core'; | ||
|
||
export default { | ||
id: 'org.nativescript.plugindemo', | ||
id: 'io.github.triniwiz.plugindemo', | ||
appResourcesPath: '../../tools/assets/App_Resources', | ||
android: { | ||
v8Flags: '--expose_gc', | ||
markingMode: 'none', | ||
}, | ||
appPath: 'src', | ||
cli: { | ||
packageManager: 'npm' | ||
packageManager: 'npm', | ||
}, | ||
hooks: [ | ||
{ | ||
type: 'before-prepare', | ||
script: '../../tools/scripts/before-prepare.js', | ||
} | ||
], | ||
type: 'before-prepare', | ||
script: '../../tools/scripts/before-prepare.js', | ||
}, | ||
], | ||
} as NativeScriptConfig; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
apps/demo/src/app.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
apps/demo/src/plugin-demos/mmkv-metal.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Observable, EventData, Page } from '@nativescript/core'; | ||
import { DemoSharedMmkvMetal } from '@demo/shared'; | ||
import { NSCMMKV as NSCMMKVMetal, initialize as initializeMetal } from '@nativescript/mmkv-metal'; | ||
|
||
import { NSCMMKV, initialize } from '@nativescript/mmkv'; | ||
|
||
export function navigatingTo(args: EventData) { | ||
const page = <Page>args.object; | ||
page.bindingContext = new DemoModel(); | ||
} | ||
|
||
const key = 'k'; | ||
const iterations = 1000; | ||
|
||
export class DemoModel extends DemoSharedMmkvMetal { | ||
mmkvm: NSCMMKVMetal; | ||
mmkv: NSCMMKVMetal; | ||
constructor() { | ||
super(); | ||
initializeMetal(); | ||
initialize(); | ||
console.time('NSCMMKV'); | ||
this.mmkv = new NSCMMKV(); | ||
console.timeEnd('NSCMMKV'); | ||
|
||
console.time('NSCMMKVMetal'); | ||
this.mmkvm = new NSCMMKVMetal(); | ||
console.timeEnd('NSCMMKVMetal'); | ||
this.mmkvm.clearAll(); | ||
this.mmkvm.clearMemoryCache(); | ||
|
||
this.mmkv.clearAll(); | ||
this.mmkv.clearMemoryCache(); | ||
|
||
this.mmkvm.set(key, 'hello'); | ||
this.bm(this.getFromMMKVM.bind(this)); | ||
|
||
this.mmkv.set(key, 'hello'); | ||
this.bm(this.getFromMMKV.bind(this)); | ||
this.mmkvm.close(); | ||
} | ||
|
||
getFromMMKV(): string | undefined { | ||
return this.mmkv.getString(key); | ||
} | ||
|
||
getFromMMKVM(): string | undefined { | ||
return this.mmkvm.getString(key); | ||
} | ||
|
||
bm(func) { | ||
try { | ||
console.log(`Starting Benchmark...`); | ||
const start = global.performance ? performance.now() : (__time() as any); | ||
for (let i = 0; i < iterations; i++) { | ||
func(); | ||
} | ||
const end = global.performance ? performance.now() : (__time() as any); | ||
const diff = end - start; | ||
console.log(`Finished Benchmark ! Took ${diff.toFixed(4)}ms!`); | ||
return diff; | ||
} catch (e) { | ||
console.error(`Failed Benchmark !`, e); | ||
return 0; | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
apps/demo/src/plugin-demos/mmkv-metal.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page"> | ||
<Page.actionBar> | ||
<ActionBar title="mmkv-metal" icon="" class="action-bar"> | ||
</ActionBar> | ||
</Page.actionBar> | ||
<StackLayout class="p-20"> | ||
<ScrollView class="h-full"> | ||
<StackLayout> | ||
<Button text="Test mmkv-metal" tap="{{ testIt }}" class="btn btn-primary"/> | ||
|
||
</StackLayout> | ||
</ScrollView> | ||
</StackLayout> | ||
</Page> |
63 changes: 63 additions & 0 deletions
apps/demo/src/plugin-demos/mmkv.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Observable, EventData, Page } from '@nativescript/core'; | ||
import { DemoSharedMmkv } from '@demo/shared'; | ||
import { NSCMMKV } from '@nativescript/mmkv'; | ||
|
||
export function navigatingTo(args: EventData) { | ||
const page = <Page>args.object; | ||
page.bindingContext = new DemoModel(); | ||
} | ||
|
||
const key = 'k'; | ||
const iterations = 1000; | ||
|
||
export class DemoModel extends DemoSharedMmkv { | ||
mmkv: NSCMMKV; | ||
constructor() { | ||
super(); | ||
this.mmkv = new NSCMMKV(); | ||
this.mmkv.clearAll(); | ||
this.mmkv.clearMemoryCache(); | ||
// this.mmkv.set('first', 'Osei'); | ||
// this.mmkv.set('age', 30); | ||
// this.mmkv.set('metal', false); | ||
|
||
// if (global.isAndroid) { | ||
// const js = new java.lang.String('Fortune'); | ||
// const buf = java.nio.ByteBuffer.wrap(js.getBytes()); | ||
// this.mmkv.set('last', (ArrayBuffer as any).from(buf as any)); | ||
// } else { | ||
// const data = NSString.stringWithString('Fortune').dataUsingEncoding(NSUTF8StringEncoding); | ||
// this.mmkv.set('last', interop.bufferFromData(data)); | ||
// } | ||
|
||
// console.log(this.mmkv.getString('first')); | ||
// console.log(this.mmkv.getNumber('age')); | ||
// console.log(this.mmkv.getBoolean('metal')); | ||
// console.log(this.mmkv.getString('last')); | ||
// console.time('test'); | ||
this.mmkv.set(key, 'hello'); | ||
this.bm(this.getFromMMKV.bind(this)); | ||
//this.mmkv.close(); | ||
} | ||
|
||
getFromMMKV(): string | undefined { | ||
return this.mmkv.getString(key); | ||
} | ||
|
||
bm(func) { | ||
try { | ||
console.log(`Starting Benchmark...`); | ||
const start = performance.now() as any; | ||
for (let i = 0; i < iterations; i++) { | ||
func(); | ||
} | ||
const end = performance.now() as any; | ||
const diff = end - start; | ||
console.log(`Finished Benchmark ! Took ${diff.toFixed(4)}ms!`); | ||
return diff; | ||
} catch (e) { | ||
console.error(`Failed Benchmark !`, e); | ||
return 0; | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
apps/demo/src/plugin-demos/mmkv.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page"> | ||
<Page.actionBar> | ||
<ActionBar title="mmkv" icon="" class="action-bar"> | ||
</ActionBar> | ||
</Page.actionBar> | ||
<StackLayout class="p-20"> | ||
<ScrollView class="h-full"> | ||
<StackLayout> | ||
<Button text="Test mmkv" tap="{{ testIt }}" class="btn btn-primary"/> | ||
|
||
</StackLayout> | ||
</ScrollView> | ||
</StackLayout> | ||
</Page> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.