react-native-xxhash 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ios/Xxhash.mm CHANGED
@@ -5,6 +5,27 @@
5
5
  #import <React/RCTUtils.h>
6
6
  #import <jsi/jsi.h>
7
7
 
8
+ #ifdef RCT_NEW_ARCH_ENABLED
9
+ #import <ReactCommon/RCTTurboModuleWithJSIBindings.h>
10
+ #import <ReactCommon/TurboModule.h>
11
+ #import <ReactCommon/CallInvoker.h>
12
+ #endif
13
+
14
+ using namespace facebook;
15
+
16
+ #ifdef RCT_NEW_ARCH_ENABLED
17
+ namespace {
18
+ class XxhashTurboModule : public facebook::react::TurboModule {
19
+ public:
20
+ XxhashTurboModule(std::shared_ptr<facebook::react::CallInvoker> jsInvoker)
21
+ : facebook::react::TurboModule("xxhash", std::move(jsInvoker)) {}
22
+ };
23
+ } // namespace
24
+
25
+ @interface Xxhash () <RCTTurboModule, RCTTurboModuleWithJSIBindings>
26
+ @end
27
+ #endif
28
+
8
29
  @implementation Xxhash
9
30
  RCT_EXPORT_MODULE(xxhash)
10
31
 
@@ -12,12 +33,19 @@ RCT_EXPORT_MODULE(xxhash)
12
33
  @synthesize methodQueue = _methodQueue;
13
34
 
14
35
  + (BOOL)requiresMainQueueSetup {
15
- return YES;
36
+ return NO;
16
37
  }
17
38
 
18
39
  RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install){
19
40
  NSLog(@"Installing JSI bindings for xxhash ...");
20
- RCTBridge* bridge = [RCTBridge currentBridge];
41
+
42
+ #ifdef RCT_NEW_ARCH_ENABLED
43
+ if (self.bridge == nil) {
44
+ return @true;
45
+ }
46
+ #endif
47
+
48
+ RCTBridge* bridge = self.bridge ?: [RCTBridge currentBridge];
21
49
  RCTCxxBridge* cxxBridge = (RCTCxxBridge*)bridge;
22
50
 
23
51
  if (cxxBridge == nil) {
@@ -34,5 +62,19 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install){
34
62
  return @true;
35
63
  }
36
64
 
65
+ #ifdef RCT_NEW_ARCH_ENABLED
66
+ - (void)installJSIBindingsWithRuntime:(jsi::Runtime &)runtime
67
+ callInvoker:(const std::shared_ptr<react::CallInvoker> &)callInvoker {
68
+ xxhash::install(&runtime);
69
+ }
70
+
71
+ - (void)installJSIBindingsWithRuntime:(jsi::Runtime &)runtime {
72
+ xxhash::install(&runtime);
73
+ }
74
+
75
+ - (std::shared_ptr<react::TurboModule>)getTurboModule:(const react::ObjCTurboModule::InitParams &)params {
76
+ return std::make_shared<XxhashTurboModule>(params.jsInvoker);
77
+ }
78
+ #endif
37
79
 
38
80
  @end
@@ -7,10 +7,13 @@ exports.hash64 = exports.hash128 = void 0;
7
7
  var _reactNative = require("react-native");
8
8
  let xxhashModule = globalThis.__xxhash128;
9
9
  if (!xxhashModule) {
10
- if (_reactNative.NativeModules.xxhash) {
11
- _reactNative.NativeModules.xxhash.install();
10
+ const XxhashModule = _reactNative.TurboModuleRegistry.get('xxhash') ?? _reactNative.NativeModules.xxhash;
11
+ if (XxhashModule) {
12
+ XxhashModule.install?.();
12
13
  xxhashModule = globalThis.__xxhash128;
13
- console.log('✅ xxhash initialized successfully');
14
+ if (xxhashModule) {
15
+ console.log('✅ xxhash initialized successfully');
16
+ }
14
17
  }
15
18
  }
16
19
 
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","xxhashModule","globalThis","__xxhash128","NativeModules","xxhash","install","console","log","hash128","input","Error","exports","hash64","__xxhash64"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAOA,IAAIC,YAAY,GAAGC,UAAU,CAACC,WAAW;AAEzC,IAAG,CAACF,YAAY,EAAC;EACf,IAAGG,0BAAa,CAACC,MAAM,EAAC;IACtBD,0BAAa,CAACC,MAAM,CAACC,OAAO,CAAC,CAAC;IAC9BL,YAAY,GAAGC,UAAU,CAACC,WAAW;IACrCI,OAAO,CAACC,GAAG,CAAC,mCAAmC,CAAC;EAClD;AACF;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACQ,MAAMC,OAAO,GAAIC,KAAa,IAAa;EACjD,IAAG,CAACA,KAAK,EAAC;IACR,MAAM,IAAIC,KAAK,CAAC,mBAAmB,CAAC;EACtC;EAEA,IAAG,OAAOD,KAAK,KAAK,QAAQ,EAAC;IAC3B,MAAM,IAAIC,KAAK,CAAC,wBAAwB,CAAC;EAC3C;EAEA,OAAOT,UAAU,CAACC,WAAW,CAACO,KAAK,CAAC;AACrC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAhBAE,OAAA,CAAAH,OAAA,GAAAA,OAAA;AAkBQ,MAAMI,MAAM,GAAIH,KAAa,IAAa;EAChD,IAAG,CAACA,KAAK,EAAC;IACR,MAAM,IAAIC,KAAK,CAAC,mBAAmB,CAAC;EACtC;EAEA,IAAG,OAAOD,KAAK,KAAK,QAAQ,EAAC;IAC3B,MAAM,IAAIC,KAAK,CAAC,wBAAwB,CAAC;EAC3C;EAEA,OAAOT,UAAU,CAACY,UAAU,CAACJ,KAAK,CAAC;AACpC,CAAC;AAAAE,OAAA,CAAAC,MAAA,GAAAA,MAAA","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","xxhashModule","globalThis","__xxhash128","XxhashModule","TurboModuleRegistry","get","NativeModules","xxhash","install","console","log","hash128","input","Error","exports","hash64","__xxhash64"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAOA,IAAIC,YAAY,GAAIC,UAAU,CAASC,WAAwD;AAE/F,IAAG,CAACF,YAAY,EAAC;EACf,MAAMG,YAAiB,GAAGC,gCAAmB,CAACC,GAAG,CAAC,QAAQ,CAAC,IAAIC,0BAAa,CAACC,MAAM;EACnF,IAAGJ,YAAY,EAAC;IACdA,YAAY,CAACK,OAAO,GAAG,CAAC;IACxBR,YAAY,GAAIC,UAAU,CAASC,WAAW;IAC9C,IAAGF,YAAY,EAAC;MACdS,OAAO,CAACC,GAAG,CAAC,mCAAmC,CAAC;IAClD;EACF;AACF;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACQ,MAAMC,OAAO,GAAIC,KAAa,IAAa;EACjD,IAAG,CAACA,KAAK,EAAC;IACR,MAAM,IAAIC,KAAK,CAAC,mBAAmB,CAAC;EACtC;EAEA,IAAG,OAAOD,KAAK,KAAK,QAAQ,EAAC;IAC3B,MAAM,IAAIC,KAAK,CAAC,wBAAwB,CAAC;EAC3C;EAEA,OAAOZ,UAAU,CAACC,WAAW,CAACU,KAAK,CAAC;AACrC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAhBAE,OAAA,CAAAH,OAAA,GAAAA,OAAA;AAkBQ,MAAMI,MAAM,GAAIH,KAAa,IAAa;EAChD,IAAG,CAACA,KAAK,EAAC;IACR,MAAM,IAAIC,KAAK,CAAC,mBAAmB,CAAC;EACtC;EAEA,IAAG,OAAOD,KAAK,KAAK,QAAQ,EAAC;IAC3B,MAAM,IAAIC,KAAK,CAAC,wBAAwB,CAAC;EAC3C;EAEA,OAAOZ,UAAU,CAACe,UAAU,CAACJ,KAAK,CAAC;AACpC,CAAC;AAAAE,OAAA,CAAAC,MAAA,GAAAA,MAAA","ignoreList":[]}
@@ -1,12 +1,15 @@
1
1
  "use strict";
2
2
 
3
- import { NativeModules } from 'react-native';
3
+ import { NativeModules, TurboModuleRegistry } from 'react-native';
4
4
  let xxhashModule = globalThis.__xxhash128;
5
5
  if (!xxhashModule) {
6
- if (NativeModules.xxhash) {
7
- NativeModules.xxhash.install();
6
+ const XxhashModule = TurboModuleRegistry.get('xxhash') ?? NativeModules.xxhash;
7
+ if (XxhashModule) {
8
+ XxhashModule.install?.();
8
9
  xxhashModule = globalThis.__xxhash128;
9
- console.log('✅ xxhash initialized successfully');
10
+ if (xxhashModule) {
11
+ console.log('✅ xxhash initialized successfully');
12
+ }
10
13
  }
11
14
  }
12
15
 
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","xxhashModule","globalThis","__xxhash128","xxhash","install","console","log","hash128","input","Error","hash64","__xxhash64"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAAQA,aAAa,QAAO,cAAc;AAO1C,IAAIC,YAAY,GAAGC,UAAU,CAACC,WAAW;AAEzC,IAAG,CAACF,YAAY,EAAC;EACf,IAAGD,aAAa,CAACI,MAAM,EAAC;IACtBJ,aAAa,CAACI,MAAM,CAACC,OAAO,CAAC,CAAC;IAC9BJ,YAAY,GAAGC,UAAU,CAACC,WAAW;IACrCG,OAAO,CAACC,GAAG,CAAC,mCAAmC,CAAC;EAClD;AACF;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACC,OAAO,MAAMC,OAAO,GAAIC,KAAa,IAAa;EACjD,IAAG,CAACA,KAAK,EAAC;IACR,MAAM,IAAIC,KAAK,CAAC,mBAAmB,CAAC;EACtC;EAEA,IAAG,OAAOD,KAAK,KAAK,QAAQ,EAAC;IAC3B,MAAM,IAAIC,KAAK,CAAC,wBAAwB,CAAC;EAC3C;EAEA,OAAOR,UAAU,CAACC,WAAW,CAACM,KAAK,CAAC;AACrC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEC,OAAO,MAAME,MAAM,GAAIF,KAAa,IAAa;EAChD,IAAG,CAACA,KAAK,EAAC;IACR,MAAM,IAAIC,KAAK,CAAC,mBAAmB,CAAC;EACtC;EAEA,IAAG,OAAOD,KAAK,KAAK,QAAQ,EAAC;IAC3B,MAAM,IAAIC,KAAK,CAAC,wBAAwB,CAAC;EAC3C;EAEA,OAAOR,UAAU,CAACU,UAAU,CAACH,KAAK,CAAC;AACpC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["NativeModules","TurboModuleRegistry","xxhashModule","globalThis","__xxhash128","XxhashModule","get","xxhash","install","console","log","hash128","input","Error","hash64","__xxhash64"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAAQA,aAAa,EAAEC,mBAAmB,QAAO,cAAc;AAO/D,IAAIC,YAAY,GAAIC,UAAU,CAASC,WAAwD;AAE/F,IAAG,CAACF,YAAY,EAAC;EACf,MAAMG,YAAiB,GAAGJ,mBAAmB,CAACK,GAAG,CAAC,QAAQ,CAAC,IAAIN,aAAa,CAACO,MAAM;EACnF,IAAGF,YAAY,EAAC;IACdA,YAAY,CAACG,OAAO,GAAG,CAAC;IACxBN,YAAY,GAAIC,UAAU,CAASC,WAAW;IAC9C,IAAGF,YAAY,EAAC;MACdO,OAAO,CAACC,GAAG,CAAC,mCAAmC,CAAC;IAClD;EACF;AACF;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACC,OAAO,MAAMC,OAAO,GAAIC,KAAa,IAAa;EACjD,IAAG,CAACA,KAAK,EAAC;IACR,MAAM,IAAIC,KAAK,CAAC,mBAAmB,CAAC;EACtC;EAEA,IAAG,OAAOD,KAAK,KAAK,QAAQ,EAAC;IAC3B,MAAM,IAAIC,KAAK,CAAC,wBAAwB,CAAC;EAC3C;EAEA,OAAOV,UAAU,CAACC,WAAW,CAACQ,KAAK,CAAC;AACrC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEC,OAAO,MAAME,MAAM,GAAIF,KAAa,IAAa;EAChD,IAAG,CAACA,KAAK,EAAC;IACR,MAAM,IAAIC,KAAK,CAAC,mBAAmB,CAAC;EACtC;EAEA,IAAG,OAAOD,KAAK,KAAK,QAAQ,EAAC;IAC3B,MAAM,IAAIC,KAAK,CAAC,wBAAwB,CAAC;EAC3C;EAEA,OAAOV,UAAU,CAACY,UAAU,CAACH,KAAK,CAAC;AACpC,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3C,IAAI,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C;AAcD;;;;;;;;;;;;;;;;GAgBG;AACF,eAAO,MAAM,OAAO,UAAW,MAAM,KAAG,MAUvC,CAAA;AAEF;;;;;;;;;;;;;;;;GAgBG;AAEF,eAAO,MAAM,MAAM,UAAW,MAAM,KAAG,MAUtC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3C,IAAI,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C;AAiBD;;;;;;;;;;;;;;;;GAgBG;AACF,eAAO,MAAM,OAAO,UAAW,MAAM,KAAG,MAUvC,CAAA;AAEF;;;;;;;;;;;;;;;;GAgBG;AAEF,eAAO,MAAM,MAAM,UAAW,MAAM,KAAG,MAUtC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-xxhash",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "💪 A high-performance React Native library for generating xxHash hashes using C++ and JSI",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "module": "./lib/module/index.js",
package/src/index.tsx CHANGED
@@ -1,17 +1,20 @@
1
- import {NativeModules} from 'react-native'
1
+ import {NativeModules, TurboModuleRegistry} from 'react-native'
2
2
  declare global {
3
3
  var __xxhash128: (input: string) => string;
4
4
  var __xxhash64: (input: string) => string;
5
5
  }
6
6
 
7
7
 
8
- let xxhashModule = globalThis.__xxhash128;
8
+ let xxhashModule = (globalThis as any).__xxhash128 as typeof globalThis.__xxhash128 | undefined;
9
9
 
10
10
  if(!xxhashModule){
11
- if(NativeModules.xxhash){
12
- NativeModules.xxhash.install();
13
- xxhashModule = globalThis.__xxhash128;
14
- console.log('✅ xxhash initialized successfully')
11
+ const XxhashModule: any = TurboModuleRegistry.get('xxhash') ?? NativeModules.xxhash;
12
+ if(XxhashModule){
13
+ XxhashModule.install?.();
14
+ xxhashModule = (globalThis as any).__xxhash128;
15
+ if(xxhashModule){
16
+ console.log('✅ xxhash initialized successfully')
17
+ }
15
18
  }
16
19
  }
17
20
 
@@ -43,7 +46,7 @@ if(!xxhashModule){
43
46
  }
44
47
 
45
48
  return globalThis.__xxhash128(input);
46
- }
49
+ }
47
50
 
48
51
  /**
49
52
  * Hashes the input string using the xxhash64 algorithm.
@@ -73,4 +76,4 @@ if(!xxhashModule){
73
76
  }
74
77
 
75
78
  return globalThis.__xxhash64(input);
76
- }
79
+ }