├── .babelrc ├── .gitignore ├── .npmignore ├── .travis.yml ├── Example ├── .babelrc ├── .buckconfig ├── .flowconfig ├── .gitattributes ├── .gitignore ├── .watchmanconfig ├── README.md ├── android │ ├── app │ │ ├── BUCK │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── firebaselocalcache │ │ │ │ ├── MainActivity.java │ │ │ │ └── MainApplication.java │ │ │ └── res │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ └── values │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── keystores │ │ ├── BUCK │ │ └── debug.keystore.properties │ └── settings.gradle ├── app.json ├── app │ ├── Helpers.js │ ├── HomeScreen.js │ ├── ViewItemScreen.js │ └── components │ │ ├── ChildAddedList.js │ │ └── ItemList.js ├── index.android.js ├── index.ios.js ├── ios │ ├── firebaseLocalCache-tvOS │ │ └── Info.plist │ ├── firebaseLocalCache-tvOSTests │ │ └── Info.plist │ ├── firebaseLocalCache.xcodeproj │ │ ├── project.pbxproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ ├── firebaseLocalCache-tvOS.xcscheme │ │ │ └── firebaseLocalCache.xcscheme │ ├── firebaseLocalCache │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Base.lproj │ │ │ └── LaunchScreen.xib │ │ ├── Images.xcassets │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── Info.plist │ │ └── main.m │ └── firebaseLocalCacheTests │ │ ├── Info.plist │ │ └── firebaseLocalCacheTests.m └── package.json ├── LICENSE ├── README.md ├── __tests__ └── index-test.js ├── dist └── index.js ├── docs └── index.md ├── package.json └── src └── index.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015", "stage-0"] 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | __tests__ 2 | coverage 3 | docs 4 | Example 5 | src 6 | .babelrc 7 | .gitignore 8 | .travis.yml 9 | LICENSE -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - stable 4 | install: 5 | - npm install 6 | script: 7 | - npm test 8 | after_script: 9 | - "cat coverage/lcov.info | node_modules/coveralls/bin/coveralls.js" 10 | -------------------------------------------------------------------------------- /Example/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["react-native"] 3 | } -------------------------------------------------------------------------------- /Example/.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /Example/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore "BUCK" generated dirs 6 | /\.buckd/ 7 | 8 | ; Ignore unexpected extra "@providesModule" 9 | .*/node_modules/.*/node_modules/fbjs/.* 10 | 11 | ; Ignore duplicate module providers 12 | ; For RN Apps installed via npm, "Libraries" folder is inside 13 | ; "node_modules/react-native" but in the source repo it is in the root 14 | .*/Libraries/react-native/React.js 15 | .*/Libraries/react-native/ReactNative.js 16 | 17 | [include] 18 | 19 | [libs] 20 | node_modules/react-native/Libraries/react-native/react-native-interface.js 21 | node_modules/react-native/flow 22 | flow/ 23 | 24 | [options] 25 | emoji=true 26 | 27 | module.system=haste 28 | 29 | experimental.strict_type_args=true 30 | 31 | munge_underscores=true 32 | 33 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' 34 | 35 | suppress_type=$FlowIssue 36 | suppress_type=$FlowFixMe 37 | suppress_type=$FixMe 38 | 39 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-0]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 40 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-0]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ 41 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 42 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 43 | 44 | unsafe.enable_getters_and_setters=true 45 | 46 | [version] 47 | ^0.40.0 48 | -------------------------------------------------------------------------------- /Example/.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | -------------------------------------------------------------------------------- /Example/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | project.xcworkspace 24 | 25 | # Android/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | 33 | # node.js 34 | # 35 | node_modules/ 36 | npm-debug.log 37 | yarn-error.log 38 | 39 | # BUCK 40 | buck-out/ 41 | \.buckd/ 42 | *.keystore 43 | 44 | # fastlane 45 | # 46 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 47 | # screenshots whenever they are needed. 48 | # For more information about the recommended setup visit: 49 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 50 | 51 | fastlane/report.xml 52 | fastlane/Preview.html 53 | fastlane/screenshots 54 | 55 | firebaseconfig.json -------------------------------------------------------------------------------- /Example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /Example/README.md: -------------------------------------------------------------------------------- 1 | # Firebase Local Cache Example 2 | 3 | ## Getting Started 4 | 5 | ### Setup a Firebase Project 6 | 7 | Mine won't be around forever, so build up a free Firebase project and get the details by ading a "Web" app on you project overview page. 8 | 9 | You'll also need to add some values to the realtime database, you can do so by copying this to a file and importing it: 10 | 11 | ```json 12 | { 13 | "items" : { 14 | "-KgCr7WHT7qJwHWdPucd" : { 15 | "description" : "this is a short description of the thing. I will make it the same for each! 1", 16 | "name" : "item 1" 17 | }, 18 | "-KgCrKOhfACgRUQ0Jqlx" : { 19 | "description" : "this is a short description of the thing. I will make it the same for each! 2", 20 | "name" : "item 2" 21 | }, 22 | "-KgEiREmxHOVSZM7WB17" : { 23 | "description" : "this is a short description of the thing. I will make it the same for each! 3", 24 | "name" : "item 3" 25 | }, 26 | "-KgGX2x6fHShZVOam48M" : { 27 | "description" : "this is a short description of the thing. I will make it the same for each! 4", 28 | "name" : "item 4" 29 | } 30 | }, 31 | "messages" : { 32 | "msg1" : { 33 | "message" : "hello" 34 | }, 35 | "msg2" : { 36 | "message" : "hi" 37 | }, 38 | "msg3" : { 39 | "message" : "how are you?" 40 | }, 41 | "msg4" : { 42 | "message" : "you should know." 43 | }, 44 | "msg5" : { 45 | "message" : "how?" 46 | }, 47 | "msg6" : { 48 | "message" : "you are me." 49 | } 50 | }, 51 | "user-items" : { 52 | "user1" : { 53 | "-KgCr7WHT7qJwHWdPucd" : { 54 | "name" : "item 1" 55 | }, 56 | "-KgEiREmxHOVSZM7WB17" : { 57 | "name" : "item 3" 58 | }, 59 | "-KgGX2x6fHShZVOam48M" : { 60 | "name" : "item 4" 61 | } 62 | } 63 | } 64 | } 65 | 66 | ``` 67 | 68 | This is, as usual, a contrived example where each user has a list of items stored in `user-items` that contains some limited information, while the majority of the info is stored in an object under `items`. For permissions, just set everything to read only: 69 | 70 | ```json 71 | { 72 | "rules": { 73 | ".read": true, 74 | ".write": "auth != null" 75 | } 76 | } 77 | ``` 78 | 79 | Run as you would any other react-native program: 80 | 81 | `react-native run-android` 82 | or 83 | `react-native run-ios` 84 | 85 | Hopefully that works... 86 | 87 | Note that recently there has been a dependency issue with the react-navigation package and as a temporary fix the package is being pulled from the latest in the GitHub repo. This will need to change. 88 | 89 | ## Notes 90 | 91 | The first time you load any screen, nothing has been cached, so both lists will take the same amount of time to load. To see the difference, open up a few items repeatedly, as well as completely quit the app and restart it to see the difference in the load time of the item list. -------------------------------------------------------------------------------- /Example/android/app/BUCK: -------------------------------------------------------------------------------- 1 | # To learn about Buck see [Docs](https://buckbuild.com/). 2 | # To run your application with Buck: 3 | # - install Buck 4 | # - `npm start` - to start the packager 5 | # - `cd android` 6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` 7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck 8 | # - `buck install -r android/app` - compile, install and run application 9 | # 10 | 11 | lib_deps = [] 12 | 13 | for jarfile in glob(['libs/*.jar']): 14 | name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')] 15 | lib_deps.append(':' + name) 16 | prebuilt_jar( 17 | name = name, 18 | binary_jar = jarfile, 19 | ) 20 | 21 | for aarfile in glob(['libs/*.aar']): 22 | name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')] 23 | lib_deps.append(':' + name) 24 | android_prebuilt_aar( 25 | name = name, 26 | aar = aarfile, 27 | ) 28 | 29 | android_library( 30 | name = "all-libs", 31 | exported_deps = lib_deps, 32 | ) 33 | 34 | android_library( 35 | name = "app-code", 36 | srcs = glob([ 37 | "src/main/java/**/*.java", 38 | ]), 39 | deps = [ 40 | ":all-libs", 41 | ":build_config", 42 | ":res", 43 | ], 44 | ) 45 | 46 | android_build_config( 47 | name = "build_config", 48 | package = "com.firebaselocalcache", 49 | ) 50 | 51 | android_resource( 52 | name = "res", 53 | package = "com.firebaselocalcache", 54 | res = "src/main/res", 55 | ) 56 | 57 | android_binary( 58 | name = "app", 59 | keystore = "//android/keystores:debug", 60 | manifest = "src/main/AndroidManifest.xml", 61 | package_type = "debug", 62 | deps = [ 63 | ":app-code", 64 | ], 65 | ) 66 | -------------------------------------------------------------------------------- /Example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | 3 | import com.android.build.OutputFile 4 | 5 | /** 6 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets 7 | * and bundleReleaseJsAndAssets). 8 | * These basically call `react-native bundle` with the correct arguments during the Android build 9 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 10 | * bundle directly from the development server. Below you can see all the possible configurations 11 | * and their defaults. If you decide to add a configuration block, make sure to add it before the 12 | * `apply from: "../../node_modules/react-native/react.gradle"` line. 13 | * 14 | * project.ext.react = [ 15 | * // the name of the generated asset file containing your JS bundle 16 | * bundleAssetName: "index.android.bundle", 17 | * 18 | * // the entry file for bundle generation 19 | * entryFile: "index.android.js", 20 | * 21 | * // whether to bundle JS and assets in debug mode 22 | * bundleInDebug: false, 23 | * 24 | * // whether to bundle JS and assets in release mode 25 | * bundleInRelease: true, 26 | * 27 | * // whether to bundle JS and assets in another build variant (if configured). 28 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants 29 | * // The configuration property can be in the following formats 30 | * // 'bundleIn${productFlavor}${buildType}' 31 | * // 'bundleIn${buildType}' 32 | * // bundleInFreeDebug: true, 33 | * // bundleInPaidRelease: true, 34 | * // bundleInBeta: true, 35 | * 36 | * // the root of your project, i.e. where "package.json" lives 37 | * root: "../../", 38 | * 39 | * // where to put the JS bundle asset in debug mode 40 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 41 | * 42 | * // where to put the JS bundle asset in release mode 43 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release", 44 | * 45 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 46 | * // require('./image.png')), in debug mode 47 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 48 | * 49 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 50 | * // require('./image.png')), in release mode 51 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 52 | * 53 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means 54 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 55 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle 56 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 57 | * // for example, you might want to remove it from here. 58 | * inputExcludes: ["android/**", "ios/**"], 59 | * 60 | * // override which node gets called and with what additional arguments 61 | * nodeExecutableAndArgs: ["node"] 62 | * 63 | * // supply additional arguments to the packager 64 | * extraPackagerArgs: [] 65 | * ] 66 | */ 67 | 68 | apply from: "../../node_modules/react-native/react.gradle" 69 | 70 | /** 71 | * Set this to true to create two separate APKs instead of one: 72 | * - An APK that only works on ARM devices 73 | * - An APK that only works on x86 devices 74 | * The advantage is the size of the APK is reduced by about 4MB. 75 | * Upload all the APKs to the Play Store and people will download 76 | * the correct one based on the CPU architecture of their device. 77 | */ 78 | def enableSeparateBuildPerCPUArchitecture = false 79 | 80 | /** 81 | * Run Proguard to shrink the Java bytecode in release builds. 82 | */ 83 | def enableProguardInReleaseBuilds = false 84 | 85 | android { 86 | compileSdkVersion 23 87 | buildToolsVersion "23.0.1" 88 | 89 | defaultConfig { 90 | applicationId "com.firebaselocalcache" 91 | minSdkVersion 16 92 | targetSdkVersion 22 93 | versionCode 1 94 | versionName "1.0" 95 | ndk { 96 | abiFilters "armeabi-v7a", "x86" 97 | } 98 | } 99 | splits { 100 | abi { 101 | reset() 102 | enable enableSeparateBuildPerCPUArchitecture 103 | universalApk false // If true, also generate a universal APK 104 | include "armeabi-v7a", "x86" 105 | } 106 | } 107 | buildTypes { 108 | release { 109 | minifyEnabled enableProguardInReleaseBuilds 110 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 111 | } 112 | } 113 | // applicationVariants are e.g. debug, release 114 | applicationVariants.all { variant -> 115 | variant.outputs.each { output -> 116 | // For each separate APK per architecture, set a unique version code as described here: 117 | // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits 118 | def versionCodes = ["armeabi-v7a":1, "x86":2] 119 | def abi = output.getFilter(OutputFile.ABI) 120 | if (abi != null) { // null for the universal-debug, universal-release variants 121 | output.versionCodeOverride = 122 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode 123 | } 124 | } 125 | } 126 | } 127 | 128 | dependencies { 129 | compile fileTree(dir: "libs", include: ["*.jar"]) 130 | compile "com.android.support:appcompat-v7:23.0.1" 131 | compile "com.facebook.react:react-native:+" // From node_modules 132 | } 133 | 134 | // Run this once to be able to run the application with BUCK 135 | // puts all compile dependencies into folder libs for BUCK to use 136 | task copyDownloadableDepsToLibs(type: Copy) { 137 | from configurations.compile 138 | into 'libs' 139 | } 140 | -------------------------------------------------------------------------------- /Example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Disabling obfuscation is useful if you collect stack traces from production crashes 20 | # (unless you are using a system that supports de-obfuscate the stack traces). 21 | -dontobfuscate 22 | 23 | # React Native 24 | 25 | # Keep our interfaces so they can be used by other ProGuard rules. 26 | # See http://sourceforge.net/p/proguard/bugs/466/ 27 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip 28 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters 29 | -keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip 30 | 31 | # Do not strip any method/class that is annotated with @DoNotStrip 32 | -keep @com.facebook.proguard.annotations.DoNotStrip class * 33 | -keep @com.facebook.common.internal.DoNotStrip class * 34 | -keepclassmembers class * { 35 | @com.facebook.proguard.annotations.DoNotStrip *; 36 | @com.facebook.common.internal.DoNotStrip *; 37 | } 38 | 39 | -keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * { 40 | void set*(***); 41 | *** get*(); 42 | } 43 | 44 | -keep class * extends com.facebook.react.bridge.JavaScriptModule { *; } 45 | -keep class * extends com.facebook.react.bridge.NativeModule { *; } 46 | -keepclassmembers,includedescriptorclasses class * { native ; } 47 | -keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; } 48 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; } 49 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; } 50 | 51 | -dontwarn com.facebook.react.** 52 | 53 | # okhttp 54 | 55 | -keepattributes Signature 56 | -keepattributes *Annotation* 57 | -keep class okhttp3.** { *; } 58 | -keep interface okhttp3.** { *; } 59 | -dontwarn okhttp3.** 60 | 61 | # okio 62 | 63 | -keep class sun.misc.Unsafe { *; } 64 | -dontwarn java.nio.file.* 65 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 66 | -dontwarn okio.** 67 | -------------------------------------------------------------------------------- /Example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 12 | 13 | 19 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Example/android/app/src/main/java/com/firebaselocalcache/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.firebaselocalcache; 2 | 3 | import com.facebook.react.ReactActivity; 4 | 5 | public class MainActivity extends ReactActivity { 6 | 7 | /** 8 | * Returns the name of the main component registered from JavaScript. 9 | * This is used to schedule rendering of the component. 10 | */ 11 | @Override 12 | protected String getMainComponentName() { 13 | return "firebaseLocalCache"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Example/android/app/src/main/java/com/firebaselocalcache/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.firebaselocalcache; 2 | 3 | import android.app.Application; 4 | 5 | import com.facebook.react.ReactApplication; 6 | import com.facebook.react.ReactNativeHost; 7 | import com.facebook.react.ReactPackage; 8 | import com.facebook.react.shell.MainReactPackage; 9 | import com.facebook.soloader.SoLoader; 10 | 11 | import java.util.Arrays; 12 | import java.util.List; 13 | 14 | public class MainApplication extends Application implements ReactApplication { 15 | 16 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 17 | @Override 18 | public boolean getUseDeveloperSupport() { 19 | return BuildConfig.DEBUG; 20 | } 21 | 22 | @Override 23 | protected List getPackages() { 24 | return Arrays.asList( 25 | new MainReactPackage() 26 | ); 27 | } 28 | }; 29 | 30 | @Override 31 | public ReactNativeHost getReactNativeHost() { 32 | return mReactNativeHost; 33 | } 34 | 35 | @Override 36 | public void onCreate() { 37 | super.onCreate(); 38 | SoLoader.init(this, /* native exopackage */ false); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cuttingsoup/react-native-firebase-local-cache/db755a66d6936710e85161ecfced56a1ea432887/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cuttingsoup/react-native-firebase-local-cache/db755a66d6936710e85161ecfced56a1ea432887/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cuttingsoup/react-native-firebase-local-cache/db755a66d6936710e85161ecfced56a1ea432887/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cuttingsoup/react-native-firebase-local-cache/db755a66d6936710e85161ecfced56a1ea432887/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | firebaseLocalCache 3 | 4 | -------------------------------------------------------------------------------- /Example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | mavenLocal() 18 | jcenter() 19 | maven { 20 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 21 | url "$rootDir/../node_modules/react-native/android" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | android.useDeprecatedNdk=true 21 | -------------------------------------------------------------------------------- /Example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cuttingsoup/react-native-firebase-local-cache/db755a66d6936710e85161ecfced56a1ea432887/Example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 6 | -------------------------------------------------------------------------------- /Example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /Example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /Example/android/keystores/BUCK: -------------------------------------------------------------------------------- 1 | keystore( 2 | name = "debug", 3 | properties = "debug.keystore.properties", 4 | store = "debug.keystore", 5 | visibility = [ 6 | "PUBLIC", 7 | ], 8 | ) 9 | -------------------------------------------------------------------------------- /Example/android/keystores/debug.keystore.properties: -------------------------------------------------------------------------------- 1 | key.store=debug.keystore 2 | key.alias=androiddebugkey 3 | key.store.password=android 4 | key.alias.password=android 5 | -------------------------------------------------------------------------------- /Example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'firebaseLocalCache' 2 | 3 | include ':app' 4 | -------------------------------------------------------------------------------- /Example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "firebaseLocalCache", 3 | "displayName": "firebaseLocalCache" 4 | } -------------------------------------------------------------------------------- /Example/app/Helpers.js: -------------------------------------------------------------------------------- 1 | import * as firebase from 'firebase'; 2 | import * as cachedListener from 'react-native-firebase-local-cache'; 3 | 4 | // Listeners for items list: 5 | 6 | export function onUserItemsListener(userId, callback, errorCallback, context) { 7 | cachedListener.onValue(firebase.database().ref().child(`user-items/${userId}`), function(snapshot) { 8 | var items = []; 9 | 10 | snapshot.forEach((child) => { 11 | items.push({ 12 | name: child.val().name, 13 | _key: child.key 14 | }); 15 | }); 16 | 17 | return items; 18 | }, callback, errorCallback, context); 19 | }; 20 | 21 | export function offItemsListener(userId) { 22 | cachedListener.offValue(firebase.database().ref().child(`user-items/${userId}`)); 23 | }; 24 | 25 | // Listeners for a specific item: 26 | 27 | export function onItemListener(itemId, callback, errorCallback, context) { 28 | cachedListener.onValue(firebase.database().ref().child('items').child(itemId), function(snapshot) { 29 | return { 30 | name: snapshot.val().name, 31 | description: snapshot.val().description, 32 | }; 33 | }, callback, errorCallback, context); 34 | }; 35 | 36 | export function offItemListener(itemId) { 37 | cachedListener.offValue(firebase.database().ref().child('items').child(itemId)); 38 | }; 39 | -------------------------------------------------------------------------------- /Example/app/HomeScreen.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | * @flow 5 | */ 6 | 7 | import React, { Component } from 'react'; 8 | import { 9 | View, 10 | Text, 11 | StyleSheet 12 | } from 'react-native'; 13 | 14 | import { NavigationActions } from 'react-navigation'; 15 | 16 | import ItemList from './components/ItemList' 17 | import ChildAddedList from './components/ChildAddedList' 18 | 19 | export default class HomeScreen extends Component { 20 | static navigationOptions = { 21 | title: 'Firebase Cache', 22 | }; 23 | 24 | constructor(props) { 25 | super(props); 26 | 27 | this._navigateToItem = this._navigateToItem.bind(this); 28 | } 29 | 30 | _navigateToItem(itemId) { 31 | this.props.navigation.navigate('ViewItem', {itemId: itemId}); 32 | } 33 | 34 | render() { 35 | const { navigate } = this.props.navigation; 36 | 37 | return ( 38 | 39 | Cached: 40 | 43 | Not Cached 44 | 47 | Cached 'child_added' 48 | 51 | Not Cached 'child_added' 52 | 55 | 56 | ); 57 | } 58 | } 59 | 60 | const styles = StyleSheet.create({ 61 | container: { 62 | flex: 1, 63 | backgroundColor: '#FAFAFA', 64 | }, 65 | }); 66 | -------------------------------------------------------------------------------- /Example/app/ViewItemScreen.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | * @flow 5 | */ 6 | 7 | import React, { Component } from 'react'; 8 | import { 9 | View, 10 | Text, 11 | StyleSheet 12 | } from 'react-native'; 13 | 14 | import { NavigationActions } from 'react-navigation'; 15 | 16 | import * as firebase from 'firebase'; 17 | 18 | import * as Helpers from './Helpers'; 19 | 20 | export default class HomeScreen extends Component { 21 | static navigationOptions = { 22 | title: 'View Item', 23 | }; 24 | 25 | constructor(props) { 26 | super(props); 27 | 28 | this.state = { 29 | cachedName: 'loading...', 30 | notCachedName: 'loading...', 31 | }; 32 | 33 | this.itemId = this.props.navigation.state.params.itemId; 34 | //In reality you would use the users uid rather than a hard coded string 'user1'. 35 | this.itemRef = firebase.database().ref().child(`items/${this.itemId}`); 36 | } 37 | 38 | componentDidMount() { 39 | //Non-cached: 40 | this.itemRef.on('value', (snap) => { 41 | this.setState({ 42 | notCachedName: snap.val().name, 43 | notCachedDescription: snap.val().description, 44 | }) 45 | }); 46 | 47 | //Cached: 48 | Helpers.onItemListener(this.itemId, (item) => { 49 | this.setState({ 50 | cachedName: item.name, 51 | cachedDescription: item.description, 52 | }) 53 | }) 54 | } 55 | 56 | componentWillUnmount() { 57 | this.itemRef.off(); 58 | Helpers.offItemListener(this.itemId); 59 | } 60 | 61 | render() { 62 | const { navigate } = this.props.navigation; 63 | 64 | return ( 65 | 66 | Cached: 67 | {this.state.cachedName} 68 | {this.state.cachedDescription} 69 | Not Cached: 70 | {this.state.notCachedName} 71 | {this.state.notCachedDescription} 72 | 73 | ); 74 | } 75 | } 76 | 77 | const styles = StyleSheet.create({ 78 | container: { 79 | flex: 1, 80 | backgroundColor: '#FAFAFA', 81 | }, 82 | bigText: { 83 | fontSize: 18 84 | } 85 | }); 86 | -------------------------------------------------------------------------------- /Example/app/components/ChildAddedList.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | * @flow 5 | */ 6 | 7 | import React, { Component } from 'react'; 8 | import { 9 | Text, 10 | View, 11 | StyleSheet, 12 | ListView, 13 | TouchableWithoutFeedback, 14 | } from 'react-native'; 15 | 16 | import { NavigationActions } from 'react-navigation'; 17 | 18 | import * as firebase from 'firebase'; 19 | 20 | import * as cachedListener from 'react-native-firebase-local-cache'; 21 | 22 | const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); 23 | 24 | export default class ChildAddedList extends Component { 25 | constructor(props) { 26 | super(props); 27 | this.state = { 28 | dataSource: ds.cloneWithRows([]), 29 | }; 30 | 31 | this.messagesRef = firebase.database().ref().child('messages'); 32 | 33 | this.messages = [] 34 | } 35 | 36 | _messageFromSnapshot(snapshot) { 37 | return { 38 | message: snapshot.val().message, 39 | _key: snapshot.key 40 | }; 41 | } 42 | 43 | componentDidMount() { 44 | if(this.props.cached) { 45 | this._startCachedListener(); 46 | } else { 47 | this._startUncachedListener(); 48 | } 49 | } 50 | 51 | _startCachedListener() { 52 | cachedListener.onChildAdded(this.messagesRef, function(cached){ 53 | // Receiving cached list of messages: 54 | this.setState({ 55 | dataSource: this.state.dataSource.cloneWithRows(cached), 56 | }); 57 | }, function() { 58 | //Clean up messages list (not required but this is where you would do it if it was) 59 | this.messages = []; 60 | }, function(snapshot) { 61 | //New snapshot available. 62 | this.messages.push(this._messageFromSnapshot(snapshot)); 63 | 64 | this.setState({ 65 | dataSource: this.state.dataSource.cloneWithRows(this.messages), 66 | }); 67 | },this); 68 | } 69 | 70 | _stopCachedListener() { 71 | //Cache the top two messages. Alternatively, use this.messages.slice(-2) for the last two - depends on how they are sorted. 72 | cachedListener.offChildAdded(this.messagesRef, this.messages.slice(0,2)); 73 | } 74 | 75 | _startUncachedListener() { 76 | this.messagesRef.on('child_added', function(snapshot) { 77 | this.messages.push(this._messageFromSnapshot(snapshot)); 78 | 79 | this.setState({ 80 | dataSource: this.state.dataSource.cloneWithRows(this.messages), 81 | }); 82 | }, this); 83 | 84 | this.messagesRef.on('child_removed', function(snapshot) { 85 | this.messages.splice(this.messages.indexOf(this._messageFromSnapshot(snapshot)), 1); 86 | }, this); 87 | } 88 | 89 | _stopUncachedListener() { 90 | this.messagesRef.off(); 91 | } 92 | 93 | componentWillUnmount() { 94 | if(this.props.cached) { 95 | this._stopCachedListener(); 96 | } else { 97 | this._stopUncachedListener(); 98 | } 99 | } 100 | 101 | _renderItem(item) { 102 | return ( 103 | 104 | 105 | {item.message} 106 | 107 | 108 | ); 109 | } 110 | 111 | render() { 112 | return ( 113 | 114 | 119 | 120 | ); 121 | } 122 | } 123 | 124 | const styles = StyleSheet.create({ 125 | container: { 126 | flex: 1, 127 | backgroundColor: '#F5FCFF', 128 | }, 129 | header:{ 130 | elevation: 2, 131 | backgroundColor: '#FEFEFE', 132 | borderBottomWidth: 1, 133 | borderBottomColor: '#CFD8DC', 134 | fontSize: 16, 135 | padding: 12, 136 | }, 137 | listview: { 138 | flex: 1, 139 | }, 140 | }); 141 | -------------------------------------------------------------------------------- /Example/app/components/ItemList.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | * @flow 5 | */ 6 | 7 | import React, { Component } from 'react'; 8 | import { 9 | Text, 10 | View, 11 | StyleSheet, 12 | ListView, 13 | TouchableWithoutFeedback, 14 | } from 'react-native'; 15 | 16 | import { NavigationActions } from 'react-navigation'; 17 | 18 | import * as firebase from 'firebase'; 19 | 20 | import * as Helpers from '../Helpers'; 21 | 22 | const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); 23 | 24 | export default class StoryList extends Component { 25 | constructor(props) { 26 | super(props); 27 | this.state = { 28 | dataSource: ds.cloneWithRows([]), 29 | }; 30 | 31 | this._navigateToItem = this._navigateToItem.bind(this); 32 | 33 | //In reality you would use the uid from Firebase, not a hard coded string :) 34 | this.userId = 'user1'; 35 | this.userItemsRef = firebase.database().ref().child(`user-items/${this.userId}`); 36 | } 37 | 38 | _navigateToItem(itemId) { 39 | this.props.onItemPress(itemId); 40 | } 41 | 42 | componentDidMount() { 43 | if(this.props.cached) { 44 | //Cached version: 45 | Helpers.onUserItemsListener(this.userId, function(items) { 46 | this.setState({ 47 | dataSource: this.state.dataSource.cloneWithRows(items), 48 | }); 49 | }, this); 50 | } else { 51 | //Non cached version: 52 | this.userItemsRef.on('value', function(snapshot) { 53 | var items = []; 54 | 55 | snapshot.forEach((child) => { 56 | items.push({ 57 | name: child.val().name, 58 | _key: child.key 59 | }); 60 | }); 61 | 62 | this.setState({ 63 | dataSource: this.state.dataSource.cloneWithRows(items), 64 | }); 65 | }, this); 66 | } 67 | } 68 | 69 | componentWillUnmount() { 70 | if(this.props.cached) { 71 | Helpers.offItemsListener(this.userId); 72 | } else { 73 | this.userItemsRef.off(); 74 | } 75 | } 76 | 77 | _renderItem(item) { 78 | return ( 79 | 80 | this._navigateToItem(item._key)}> 82 | 83 | 84 | {item.name} 85 | 86 | 87 | 88 | 89 | ); 90 | } 91 | 92 | render() { 93 | return ( 94 | 95 | 100 | 101 | ); 102 | } 103 | } 104 | 105 | const styles = StyleSheet.create({ 106 | container: { 107 | flex: 1, 108 | backgroundColor: '#F5FCFF', 109 | }, 110 | header:{ 111 | elevation: 2, 112 | backgroundColor: '#FEFEFE', 113 | borderBottomWidth: 1, 114 | borderBottomColor: '#CFD8DC', 115 | fontSize: 16, 116 | padding: 12, 117 | }, 118 | listview: { 119 | flex: 1, 120 | }, 121 | }); 122 | -------------------------------------------------------------------------------- /Example/index.android.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | * @flow 5 | */ 6 | 7 | import React, { Component } from 'react'; 8 | import { 9 | AppRegistry, 10 | } from 'react-native'; 11 | 12 | import { StackNavigator } from 'react-navigation'; 13 | 14 | import * as firebase from 'firebase'; 15 | 16 | const config = { 17 | apiKey: "", 18 | authDomain: "", 19 | databaseURL: "", 21 | messagingSenderId: "" 22 | }; 23 | 24 | firebase.initializeApp(config); 25 | 26 | import HomeScreen from './app/HomeScreen' 27 | import ViewItemScreen from './app/ViewItemScreen' 28 | 29 | const firebaseLocalCache = StackNavigator({ 30 | Home: { screen: HomeScreen }, 31 | ViewItem: { screen: ViewItemScreen }, 32 | }); 33 | 34 | AppRegistry.registerComponent('firebaseLocalCache', () => firebaseLocalCache); 35 | -------------------------------------------------------------------------------- /Example/index.ios.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | * @flow 5 | */ 6 | 7 | import React, { Component } from 'react'; 8 | import { 9 | AppRegistry, 10 | } from 'react-native'; 11 | 12 | import { StackNavigator } from 'react-navigation'; 13 | 14 | import * as firebase from 'firebase'; 15 | 16 | const config = { 17 | apiKey: "", 18 | authDomain: "", 19 | databaseURL: "", 21 | messagingSenderId: "" 22 | }; 23 | 24 | firebase.initializeApp(config); 25 | 26 | import HomeScreen from './app/HomeScreen' 27 | import ViewItemScreen from './app/ViewItemScreen' 28 | 29 | const firebaseLocalCache = StackNavigator({ 30 | Home: { screen: HomeScreen }, 31 | ViewItem: { screen: ViewItemScreen }, 32 | }); 33 | 34 | AppRegistry.registerComponent('firebaseLocalCache', () => firebaseLocalCache); 35 | -------------------------------------------------------------------------------- /Example/ios/firebaseLocalCache-tvOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UIViewControllerBasedStatusBarAppearance 38 | 39 | NSLocationWhenInUseUsageDescription 40 | 41 | NSAppTransportSecurity 42 | 43 | 44 | NSExceptionDomains 45 | 46 | localhost 47 | 48 | NSExceptionAllowsInsecureHTTPLoads 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /Example/ios/firebaseLocalCache-tvOSTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Example/ios/firebaseLocalCache.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; }; 11 | 00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */; }; 12 | 00C302E81ABCBA2D00DB3ED1 /* libRCTImage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302C01ABCB91800DB3ED1 /* libRCTImage.a */; }; 13 | 00C302E91ABCBA2D00DB3ED1 /* libRCTNetwork.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302DC1ABCB9D200DB3ED1 /* libRCTNetwork.a */; }; 14 | 00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302E41ABCB9EE00DB3ED1 /* libRCTVibration.a */; }; 15 | 00E356F31AD99517003FC87E /* firebaseLocalCacheTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* firebaseLocalCacheTests.m */; }; 16 | 133E29F31AD74F7200F7D852 /* libRCTLinking.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 78C398B91ACF4ADC00677621 /* libRCTLinking.a */; }; 17 | 139105C61AF99C1200B5F7CC /* libRCTSettings.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 139105C11AF99BAD00B5F7CC /* libRCTSettings.a */; }; 18 | 139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 139FDEF41B06529B00C62182 /* libRCTWebSocket.a */; }; 19 | 13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; }; 20 | 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB11A68108700A75B9A /* LaunchScreen.xib */; }; 21 | 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 22 | 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; 23 | 140ED2AC1D01E1AD002B40FF /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; }; 24 | 146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; }; 25 | 2D02E4BC1E0B4A80006451C7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; }; 26 | 2D02E4BD1E0B4A84006451C7 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 27 | 2D02E4BF1E0B4AB3006451C7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; 28 | 2D02E4C21E0B4AEC006451C7 /* libRCTAnimation-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E9157351DD0AC6500FF2AA8 /* libRCTAnimation-tvOS.a */; }; 29 | 2D02E4C31E0B4AEC006451C7 /* libRCTImage-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3E841DF850E9000B6D8A /* libRCTImage-tvOS.a */; }; 30 | 2D02E4C41E0B4AEC006451C7 /* libRCTLinking-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3E881DF850E9000B6D8A /* libRCTLinking-tvOS.a */; }; 31 | 2D02E4C51E0B4AEC006451C7 /* libRCTNetwork-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3E8C1DF850E9000B6D8A /* libRCTNetwork-tvOS.a */; }; 32 | 2D02E4C61E0B4AEC006451C7 /* libRCTSettings-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3E901DF850E9000B6D8A /* libRCTSettings-tvOS.a */; }; 33 | 2D02E4C71E0B4AEC006451C7 /* libRCTText-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3E941DF850E9000B6D8A /* libRCTText-tvOS.a */; }; 34 | 2D02E4C81E0B4AEC006451C7 /* libRCTWebSocket-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3E991DF850E9000B6D8A /* libRCTWebSocket-tvOS.a */; }; 35 | 2D02E4C91E0B4AEC006451C7 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3EA31DF850E9000B6D8A /* libReact.a */; }; 36 | 2DCD954D1E0B4F2C00145EB5 /* firebaseLocalCacheTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* firebaseLocalCacheTests.m */; }; 37 | 5E9157361DD0AC6A00FF2AA8 /* libRCTAnimation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E9157331DD0AC6500FF2AA8 /* libRCTAnimation.a */; }; 38 | 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; }; 39 | /* End PBXBuildFile section */ 40 | 41 | /* Begin PBXContainerItemProxy section */ 42 | 00C302AB1ABCB8CE00DB3ED1 /* PBXContainerItemProxy */ = { 43 | isa = PBXContainerItemProxy; 44 | containerPortal = 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */; 45 | proxyType = 2; 46 | remoteGlobalIDString = 134814201AA4EA6300B7C361; 47 | remoteInfo = RCTActionSheet; 48 | }; 49 | 00C302B91ABCB90400DB3ED1 /* PBXContainerItemProxy */ = { 50 | isa = PBXContainerItemProxy; 51 | containerPortal = 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */; 52 | proxyType = 2; 53 | remoteGlobalIDString = 134814201AA4EA6300B7C361; 54 | remoteInfo = RCTGeolocation; 55 | }; 56 | 00C302BF1ABCB91800DB3ED1 /* PBXContainerItemProxy */ = { 57 | isa = PBXContainerItemProxy; 58 | containerPortal = 00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */; 59 | proxyType = 2; 60 | remoteGlobalIDString = 58B5115D1A9E6B3D00147676; 61 | remoteInfo = RCTImage; 62 | }; 63 | 00C302DB1ABCB9D200DB3ED1 /* PBXContainerItemProxy */ = { 64 | isa = PBXContainerItemProxy; 65 | containerPortal = 00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */; 66 | proxyType = 2; 67 | remoteGlobalIDString = 58B511DB1A9E6C8500147676; 68 | remoteInfo = RCTNetwork; 69 | }; 70 | 00C302E31ABCB9EE00DB3ED1 /* PBXContainerItemProxy */ = { 71 | isa = PBXContainerItemProxy; 72 | containerPortal = 00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */; 73 | proxyType = 2; 74 | remoteGlobalIDString = 832C81801AAF6DEF007FA2F7; 75 | remoteInfo = RCTVibration; 76 | }; 77 | 00E356F41AD99517003FC87E /* PBXContainerItemProxy */ = { 78 | isa = PBXContainerItemProxy; 79 | containerPortal = 83CBB9F71A601CBA00E9B192 /* Project object */; 80 | proxyType = 1; 81 | remoteGlobalIDString = 13B07F861A680F5B00A75B9A; 82 | remoteInfo = firebaseLocalCache; 83 | }; 84 | 139105C01AF99BAD00B5F7CC /* PBXContainerItemProxy */ = { 85 | isa = PBXContainerItemProxy; 86 | containerPortal = 139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */; 87 | proxyType = 2; 88 | remoteGlobalIDString = 134814201AA4EA6300B7C361; 89 | remoteInfo = RCTSettings; 90 | }; 91 | 139FDEF31B06529B00C62182 /* PBXContainerItemProxy */ = { 92 | isa = PBXContainerItemProxy; 93 | containerPortal = 139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */; 94 | proxyType = 2; 95 | remoteGlobalIDString = 3C86DF461ADF2C930047B81A; 96 | remoteInfo = RCTWebSocket; 97 | }; 98 | 146834031AC3E56700842450 /* PBXContainerItemProxy */ = { 99 | isa = PBXContainerItemProxy; 100 | containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */; 101 | proxyType = 2; 102 | remoteGlobalIDString = 83CBBA2E1A601D0E00E9B192; 103 | remoteInfo = React; 104 | }; 105 | 2D02E4911E0B4A5D006451C7 /* PBXContainerItemProxy */ = { 106 | isa = PBXContainerItemProxy; 107 | containerPortal = 83CBB9F71A601CBA00E9B192 /* Project object */; 108 | proxyType = 1; 109 | remoteGlobalIDString = 2D02E47A1E0B4A5D006451C7; 110 | remoteInfo = "firebaseLocalCache-tvOS"; 111 | }; 112 | 3DAD3E831DF850E9000B6D8A /* PBXContainerItemProxy */ = { 113 | isa = PBXContainerItemProxy; 114 | containerPortal = 00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */; 115 | proxyType = 2; 116 | remoteGlobalIDString = 2D2A283A1D9B042B00D4039D; 117 | remoteInfo = "RCTImage-tvOS"; 118 | }; 119 | 3DAD3E871DF850E9000B6D8A /* PBXContainerItemProxy */ = { 120 | isa = PBXContainerItemProxy; 121 | containerPortal = 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */; 122 | proxyType = 2; 123 | remoteGlobalIDString = 2D2A28471D9B043800D4039D; 124 | remoteInfo = "RCTLinking-tvOS"; 125 | }; 126 | 3DAD3E8B1DF850E9000B6D8A /* PBXContainerItemProxy */ = { 127 | isa = PBXContainerItemProxy; 128 | containerPortal = 00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */; 129 | proxyType = 2; 130 | remoteGlobalIDString = 2D2A28541D9B044C00D4039D; 131 | remoteInfo = "RCTNetwork-tvOS"; 132 | }; 133 | 3DAD3E8F1DF850E9000B6D8A /* PBXContainerItemProxy */ = { 134 | isa = PBXContainerItemProxy; 135 | containerPortal = 139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */; 136 | proxyType = 2; 137 | remoteGlobalIDString = 2D2A28611D9B046600D4039D; 138 | remoteInfo = "RCTSettings-tvOS"; 139 | }; 140 | 3DAD3E931DF850E9000B6D8A /* PBXContainerItemProxy */ = { 141 | isa = PBXContainerItemProxy; 142 | containerPortal = 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */; 143 | proxyType = 2; 144 | remoteGlobalIDString = 2D2A287B1D9B048500D4039D; 145 | remoteInfo = "RCTText-tvOS"; 146 | }; 147 | 3DAD3E981DF850E9000B6D8A /* PBXContainerItemProxy */ = { 148 | isa = PBXContainerItemProxy; 149 | containerPortal = 139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */; 150 | proxyType = 2; 151 | remoteGlobalIDString = 2D2A28881D9B049200D4039D; 152 | remoteInfo = "RCTWebSocket-tvOS"; 153 | }; 154 | 3DAD3EA21DF850E9000B6D8A /* PBXContainerItemProxy */ = { 155 | isa = PBXContainerItemProxy; 156 | containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */; 157 | proxyType = 2; 158 | remoteGlobalIDString = 2D2A28131D9B038B00D4039D; 159 | remoteInfo = "React-tvOS"; 160 | }; 161 | 3DAD3EA41DF850E9000B6D8A /* PBXContainerItemProxy */ = { 162 | isa = PBXContainerItemProxy; 163 | containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */; 164 | proxyType = 2; 165 | remoteGlobalIDString = 3D3C059A1DE3340900C268FA; 166 | remoteInfo = yoga; 167 | }; 168 | 3DAD3EA61DF850E9000B6D8A /* PBXContainerItemProxy */ = { 169 | isa = PBXContainerItemProxy; 170 | containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */; 171 | proxyType = 2; 172 | remoteGlobalIDString = 3D3C06751DE3340C00C268FA; 173 | remoteInfo = "yoga-tvOS"; 174 | }; 175 | 3DAD3EA81DF850E9000B6D8A /* PBXContainerItemProxy */ = { 176 | isa = PBXContainerItemProxy; 177 | containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */; 178 | proxyType = 2; 179 | remoteGlobalIDString = 3D3CD9251DE5FBEC00167DC4; 180 | remoteInfo = cxxreact; 181 | }; 182 | 3DAD3EAA1DF850E9000B6D8A /* PBXContainerItemProxy */ = { 183 | isa = PBXContainerItemProxy; 184 | containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */; 185 | proxyType = 2; 186 | remoteGlobalIDString = 3D3CD9321DE5FBEE00167DC4; 187 | remoteInfo = "cxxreact-tvOS"; 188 | }; 189 | 3DAD3EAC1DF850E9000B6D8A /* PBXContainerItemProxy */ = { 190 | isa = PBXContainerItemProxy; 191 | containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */; 192 | proxyType = 2; 193 | remoteGlobalIDString = 3D3CD90B1DE5FBD600167DC4; 194 | remoteInfo = jschelpers; 195 | }; 196 | 3DAD3EAE1DF850E9000B6D8A /* PBXContainerItemProxy */ = { 197 | isa = PBXContainerItemProxy; 198 | containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */; 199 | proxyType = 2; 200 | remoteGlobalIDString = 3D3CD9181DE5FBD800167DC4; 201 | remoteInfo = "jschelpers-tvOS"; 202 | }; 203 | 5E9157321DD0AC6500FF2AA8 /* PBXContainerItemProxy */ = { 204 | isa = PBXContainerItemProxy; 205 | containerPortal = 5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */; 206 | proxyType = 2; 207 | remoteGlobalIDString = 134814201AA4EA6300B7C361; 208 | remoteInfo = RCTAnimation; 209 | }; 210 | 5E9157341DD0AC6500FF2AA8 /* PBXContainerItemProxy */ = { 211 | isa = PBXContainerItemProxy; 212 | containerPortal = 5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */; 213 | proxyType = 2; 214 | remoteGlobalIDString = 2D2A28201D9B03D100D4039D; 215 | remoteInfo = "RCTAnimation-tvOS"; 216 | }; 217 | 78C398B81ACF4ADC00677621 /* PBXContainerItemProxy */ = { 218 | isa = PBXContainerItemProxy; 219 | containerPortal = 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */; 220 | proxyType = 2; 221 | remoteGlobalIDString = 134814201AA4EA6300B7C361; 222 | remoteInfo = RCTLinking; 223 | }; 224 | 832341B41AAA6A8300B99B32 /* PBXContainerItemProxy */ = { 225 | isa = PBXContainerItemProxy; 226 | containerPortal = 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */; 227 | proxyType = 2; 228 | remoteGlobalIDString = 58B5119B1A9E6C1200147676; 229 | remoteInfo = RCTText; 230 | }; 231 | /* End PBXContainerItemProxy section */ 232 | 233 | /* Begin PBXFileReference section */ 234 | 008F07F21AC5B25A0029DE68 /* main.jsbundle */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = main.jsbundle; sourceTree = ""; }; 235 | 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTActionSheet.xcodeproj; path = "../node_modules/react-native/Libraries/ActionSheetIOS/RCTActionSheet.xcodeproj"; sourceTree = ""; }; 236 | 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTGeolocation.xcodeproj; path = "../node_modules/react-native/Libraries/Geolocation/RCTGeolocation.xcodeproj"; sourceTree = ""; }; 237 | 00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTImage.xcodeproj; path = "../node_modules/react-native/Libraries/Image/RCTImage.xcodeproj"; sourceTree = ""; }; 238 | 00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = "../node_modules/react-native/Libraries/Network/RCTNetwork.xcodeproj"; sourceTree = ""; }; 239 | 00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTVibration.xcodeproj; path = "../node_modules/react-native/Libraries/Vibration/RCTVibration.xcodeproj"; sourceTree = ""; }; 240 | 00E356EE1AD99517003FC87E /* firebaseLocalCacheTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = firebaseLocalCacheTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 241 | 00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 242 | 00E356F21AD99517003FC87E /* firebaseLocalCacheTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = firebaseLocalCacheTests.m; sourceTree = ""; }; 243 | 139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTSettings.xcodeproj; path = "../node_modules/react-native/Libraries/Settings/RCTSettings.xcodeproj"; sourceTree = ""; }; 244 | 139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocket.xcodeproj; path = "../node_modules/react-native/Libraries/WebSocket/RCTWebSocket.xcodeproj"; sourceTree = ""; }; 245 | 13B07F961A680F5B00A75B9A /* firebaseLocalCache.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = firebaseLocalCache.app; sourceTree = BUILT_PRODUCTS_DIR; }; 246 | 13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = firebaseLocalCache/AppDelegate.h; sourceTree = ""; }; 247 | 13B07FB01A68108700A75B9A /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = firebaseLocalCache/AppDelegate.m; sourceTree = ""; }; 248 | 13B07FB21A68108700A75B9A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 249 | 13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = firebaseLocalCache/Images.xcassets; sourceTree = ""; }; 250 | 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = firebaseLocalCache/Info.plist; sourceTree = ""; }; 251 | 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = firebaseLocalCache/main.m; sourceTree = ""; }; 252 | 146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = ""; }; 253 | 2D02E47B1E0B4A5D006451C7 /* firebaseLocalCache-tvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "firebaseLocalCache-tvOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 254 | 2D02E4901E0B4A5D006451C7 /* firebaseLocalCache-tvOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "firebaseLocalCache-tvOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 255 | 5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = "../node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj"; sourceTree = ""; }; 256 | 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = ""; }; 257 | 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = ""; }; 258 | /* End PBXFileReference section */ 259 | 260 | /* Begin PBXFrameworksBuildPhase section */ 261 | 00E356EB1AD99517003FC87E /* Frameworks */ = { 262 | isa = PBXFrameworksBuildPhase; 263 | buildActionMask = 2147483647; 264 | files = ( 265 | 140ED2AC1D01E1AD002B40FF /* libReact.a in Frameworks */, 266 | ); 267 | runOnlyForDeploymentPostprocessing = 0; 268 | }; 269 | 13B07F8C1A680F5B00A75B9A /* Frameworks */ = { 270 | isa = PBXFrameworksBuildPhase; 271 | buildActionMask = 2147483647; 272 | files = ( 273 | 146834051AC3E58100842450 /* libReact.a in Frameworks */, 274 | 5E9157361DD0AC6A00FF2AA8 /* libRCTAnimation.a in Frameworks */, 275 | 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */, 276 | 00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */, 277 | 00C302E81ABCBA2D00DB3ED1 /* libRCTImage.a in Frameworks */, 278 | 133E29F31AD74F7200F7D852 /* libRCTLinking.a in Frameworks */, 279 | 00C302E91ABCBA2D00DB3ED1 /* libRCTNetwork.a in Frameworks */, 280 | 139105C61AF99C1200B5F7CC /* libRCTSettings.a in Frameworks */, 281 | 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */, 282 | 00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */, 283 | 139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */, 284 | ); 285 | runOnlyForDeploymentPostprocessing = 0; 286 | }; 287 | 2D02E4781E0B4A5D006451C7 /* Frameworks */ = { 288 | isa = PBXFrameworksBuildPhase; 289 | buildActionMask = 2147483647; 290 | files = ( 291 | 2D02E4C91E0B4AEC006451C7 /* libReact.a in Frameworks */, 292 | 2D02E4C21E0B4AEC006451C7 /* libRCTAnimation-tvOS.a in Frameworks */, 293 | 2D02E4C31E0B4AEC006451C7 /* libRCTImage-tvOS.a in Frameworks */, 294 | 2D02E4C41E0B4AEC006451C7 /* libRCTLinking-tvOS.a in Frameworks */, 295 | 2D02E4C51E0B4AEC006451C7 /* libRCTNetwork-tvOS.a in Frameworks */, 296 | 2D02E4C61E0B4AEC006451C7 /* libRCTSettings-tvOS.a in Frameworks */, 297 | 2D02E4C71E0B4AEC006451C7 /* libRCTText-tvOS.a in Frameworks */, 298 | 2D02E4C81E0B4AEC006451C7 /* libRCTWebSocket-tvOS.a in Frameworks */, 299 | ); 300 | runOnlyForDeploymentPostprocessing = 0; 301 | }; 302 | 2D02E48D1E0B4A5D006451C7 /* Frameworks */ = { 303 | isa = PBXFrameworksBuildPhase; 304 | buildActionMask = 2147483647; 305 | files = ( 306 | ); 307 | runOnlyForDeploymentPostprocessing = 0; 308 | }; 309 | /* End PBXFrameworksBuildPhase section */ 310 | 311 | /* Begin PBXGroup section */ 312 | 00C302A81ABCB8CE00DB3ED1 /* Products */ = { 313 | isa = PBXGroup; 314 | children = ( 315 | 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */, 316 | ); 317 | name = Products; 318 | sourceTree = ""; 319 | }; 320 | 00C302B61ABCB90400DB3ED1 /* Products */ = { 321 | isa = PBXGroup; 322 | children = ( 323 | 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */, 324 | ); 325 | name = Products; 326 | sourceTree = ""; 327 | }; 328 | 00C302BC1ABCB91800DB3ED1 /* Products */ = { 329 | isa = PBXGroup; 330 | children = ( 331 | 00C302C01ABCB91800DB3ED1 /* libRCTImage.a */, 332 | 3DAD3E841DF850E9000B6D8A /* libRCTImage-tvOS.a */, 333 | ); 334 | name = Products; 335 | sourceTree = ""; 336 | }; 337 | 00C302D41ABCB9D200DB3ED1 /* Products */ = { 338 | isa = PBXGroup; 339 | children = ( 340 | 00C302DC1ABCB9D200DB3ED1 /* libRCTNetwork.a */, 341 | 3DAD3E8C1DF850E9000B6D8A /* libRCTNetwork-tvOS.a */, 342 | ); 343 | name = Products; 344 | sourceTree = ""; 345 | }; 346 | 00C302E01ABCB9EE00DB3ED1 /* Products */ = { 347 | isa = PBXGroup; 348 | children = ( 349 | 00C302E41ABCB9EE00DB3ED1 /* libRCTVibration.a */, 350 | ); 351 | name = Products; 352 | sourceTree = ""; 353 | }; 354 | 00E356EF1AD99517003FC87E /* firebaseLocalCacheTests */ = { 355 | isa = PBXGroup; 356 | children = ( 357 | 00E356F21AD99517003FC87E /* firebaseLocalCacheTests.m */, 358 | 00E356F01AD99517003FC87E /* Supporting Files */, 359 | ); 360 | path = firebaseLocalCacheTests; 361 | sourceTree = ""; 362 | }; 363 | 00E356F01AD99517003FC87E /* Supporting Files */ = { 364 | isa = PBXGroup; 365 | children = ( 366 | 00E356F11AD99517003FC87E /* Info.plist */, 367 | ); 368 | name = "Supporting Files"; 369 | sourceTree = ""; 370 | }; 371 | 139105B71AF99BAD00B5F7CC /* Products */ = { 372 | isa = PBXGroup; 373 | children = ( 374 | 139105C11AF99BAD00B5F7CC /* libRCTSettings.a */, 375 | 3DAD3E901DF850E9000B6D8A /* libRCTSettings-tvOS.a */, 376 | ); 377 | name = Products; 378 | sourceTree = ""; 379 | }; 380 | 139FDEE71B06529A00C62182 /* Products */ = { 381 | isa = PBXGroup; 382 | children = ( 383 | 139FDEF41B06529B00C62182 /* libRCTWebSocket.a */, 384 | 3DAD3E991DF850E9000B6D8A /* libRCTWebSocket-tvOS.a */, 385 | ); 386 | name = Products; 387 | sourceTree = ""; 388 | }; 389 | 13B07FAE1A68108700A75B9A /* firebaseLocalCache */ = { 390 | isa = PBXGroup; 391 | children = ( 392 | 008F07F21AC5B25A0029DE68 /* main.jsbundle */, 393 | 13B07FAF1A68108700A75B9A /* AppDelegate.h */, 394 | 13B07FB01A68108700A75B9A /* AppDelegate.m */, 395 | 13B07FB51A68108700A75B9A /* Images.xcassets */, 396 | 13B07FB61A68108700A75B9A /* Info.plist */, 397 | 13B07FB11A68108700A75B9A /* LaunchScreen.xib */, 398 | 13B07FB71A68108700A75B9A /* main.m */, 399 | ); 400 | name = firebaseLocalCache; 401 | sourceTree = ""; 402 | }; 403 | 146834001AC3E56700842450 /* Products */ = { 404 | isa = PBXGroup; 405 | children = ( 406 | 146834041AC3E56700842450 /* libReact.a */, 407 | 3DAD3EA31DF850E9000B6D8A /* libReact.a */, 408 | 3DAD3EA51DF850E9000B6D8A /* libyoga.a */, 409 | 3DAD3EA71DF850E9000B6D8A /* libyoga.a */, 410 | 3DAD3EA91DF850E9000B6D8A /* libcxxreact.a */, 411 | 3DAD3EAB1DF850E9000B6D8A /* libcxxreact.a */, 412 | 3DAD3EAD1DF850E9000B6D8A /* libjschelpers.a */, 413 | 3DAD3EAF1DF850E9000B6D8A /* libjschelpers.a */, 414 | ); 415 | name = Products; 416 | sourceTree = ""; 417 | }; 418 | 5E91572E1DD0AC6500FF2AA8 /* Products */ = { 419 | isa = PBXGroup; 420 | children = ( 421 | 5E9157331DD0AC6500FF2AA8 /* libRCTAnimation.a */, 422 | 5E9157351DD0AC6500FF2AA8 /* libRCTAnimation-tvOS.a */, 423 | ); 424 | name = Products; 425 | sourceTree = ""; 426 | }; 427 | 78C398B11ACF4ADC00677621 /* Products */ = { 428 | isa = PBXGroup; 429 | children = ( 430 | 78C398B91ACF4ADC00677621 /* libRCTLinking.a */, 431 | 3DAD3E881DF850E9000B6D8A /* libRCTLinking-tvOS.a */, 432 | ); 433 | name = Products; 434 | sourceTree = ""; 435 | }; 436 | 832341AE1AAA6A7D00B99B32 /* Libraries */ = { 437 | isa = PBXGroup; 438 | children = ( 439 | 5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */, 440 | 146833FF1AC3E56700842450 /* React.xcodeproj */, 441 | 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */, 442 | 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */, 443 | 00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */, 444 | 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */, 445 | 00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */, 446 | 139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */, 447 | 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */, 448 | 00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */, 449 | 139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */, 450 | ); 451 | name = Libraries; 452 | sourceTree = ""; 453 | }; 454 | 832341B11AAA6A8300B99B32 /* Products */ = { 455 | isa = PBXGroup; 456 | children = ( 457 | 832341B51AAA6A8300B99B32 /* libRCTText.a */, 458 | 3DAD3E941DF850E9000B6D8A /* libRCTText-tvOS.a */, 459 | ); 460 | name = Products; 461 | sourceTree = ""; 462 | }; 463 | 83CBB9F61A601CBA00E9B192 = { 464 | isa = PBXGroup; 465 | children = ( 466 | 13B07FAE1A68108700A75B9A /* firebaseLocalCache */, 467 | 832341AE1AAA6A7D00B99B32 /* Libraries */, 468 | 00E356EF1AD99517003FC87E /* firebaseLocalCacheTests */, 469 | 83CBBA001A601CBA00E9B192 /* Products */, 470 | ); 471 | indentWidth = 2; 472 | sourceTree = ""; 473 | tabWidth = 2; 474 | }; 475 | 83CBBA001A601CBA00E9B192 /* Products */ = { 476 | isa = PBXGroup; 477 | children = ( 478 | 13B07F961A680F5B00A75B9A /* firebaseLocalCache.app */, 479 | 00E356EE1AD99517003FC87E /* firebaseLocalCacheTests.xctest */, 480 | 2D02E47B1E0B4A5D006451C7 /* firebaseLocalCache-tvOS.app */, 481 | 2D02E4901E0B4A5D006451C7 /* firebaseLocalCache-tvOSTests.xctest */, 482 | ); 483 | name = Products; 484 | sourceTree = ""; 485 | }; 486 | /* End PBXGroup section */ 487 | 488 | /* Begin PBXNativeTarget section */ 489 | 00E356ED1AD99517003FC87E /* firebaseLocalCacheTests */ = { 490 | isa = PBXNativeTarget; 491 | buildConfigurationList = 00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "firebaseLocalCacheTests" */; 492 | buildPhases = ( 493 | 00E356EA1AD99517003FC87E /* Sources */, 494 | 00E356EB1AD99517003FC87E /* Frameworks */, 495 | 00E356EC1AD99517003FC87E /* Resources */, 496 | ); 497 | buildRules = ( 498 | ); 499 | dependencies = ( 500 | 00E356F51AD99517003FC87E /* PBXTargetDependency */, 501 | ); 502 | name = firebaseLocalCacheTests; 503 | productName = firebaseLocalCacheTests; 504 | productReference = 00E356EE1AD99517003FC87E /* firebaseLocalCacheTests.xctest */; 505 | productType = "com.apple.product-type.bundle.unit-test"; 506 | }; 507 | 13B07F861A680F5B00A75B9A /* firebaseLocalCache */ = { 508 | isa = PBXNativeTarget; 509 | buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "firebaseLocalCache" */; 510 | buildPhases = ( 511 | 13B07F871A680F5B00A75B9A /* Sources */, 512 | 13B07F8C1A680F5B00A75B9A /* Frameworks */, 513 | 13B07F8E1A680F5B00A75B9A /* Resources */, 514 | 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */, 515 | ); 516 | buildRules = ( 517 | ); 518 | dependencies = ( 519 | ); 520 | name = firebaseLocalCache; 521 | productName = "Hello World"; 522 | productReference = 13B07F961A680F5B00A75B9A /* firebaseLocalCache.app */; 523 | productType = "com.apple.product-type.application"; 524 | }; 525 | 2D02E47A1E0B4A5D006451C7 /* firebaseLocalCache-tvOS */ = { 526 | isa = PBXNativeTarget; 527 | buildConfigurationList = 2D02E4BA1E0B4A5E006451C7 /* Build configuration list for PBXNativeTarget "firebaseLocalCache-tvOS" */; 528 | buildPhases = ( 529 | 2D02E4771E0B4A5D006451C7 /* Sources */, 530 | 2D02E4781E0B4A5D006451C7 /* Frameworks */, 531 | 2D02E4791E0B4A5D006451C7 /* Resources */, 532 | 2D02E4CB1E0B4B27006451C7 /* Bundle React Native Code And Images */, 533 | ); 534 | buildRules = ( 535 | ); 536 | dependencies = ( 537 | ); 538 | name = "firebaseLocalCache-tvOS"; 539 | productName = "firebaseLocalCache-tvOS"; 540 | productReference = 2D02E47B1E0B4A5D006451C7 /* firebaseLocalCache-tvOS.app */; 541 | productType = "com.apple.product-type.application"; 542 | }; 543 | 2D02E48F1E0B4A5D006451C7 /* firebaseLocalCache-tvOSTests */ = { 544 | isa = PBXNativeTarget; 545 | buildConfigurationList = 2D02E4BB1E0B4A5E006451C7 /* Build configuration list for PBXNativeTarget "firebaseLocalCache-tvOSTests" */; 546 | buildPhases = ( 547 | 2D02E48C1E0B4A5D006451C7 /* Sources */, 548 | 2D02E48D1E0B4A5D006451C7 /* Frameworks */, 549 | 2D02E48E1E0B4A5D006451C7 /* Resources */, 550 | ); 551 | buildRules = ( 552 | ); 553 | dependencies = ( 554 | 2D02E4921E0B4A5D006451C7 /* PBXTargetDependency */, 555 | ); 556 | name = "firebaseLocalCache-tvOSTests"; 557 | productName = "firebaseLocalCache-tvOSTests"; 558 | productReference = 2D02E4901E0B4A5D006451C7 /* firebaseLocalCache-tvOSTests.xctest */; 559 | productType = "com.apple.product-type.bundle.unit-test"; 560 | }; 561 | /* End PBXNativeTarget section */ 562 | 563 | /* Begin PBXProject section */ 564 | 83CBB9F71A601CBA00E9B192 /* Project object */ = { 565 | isa = PBXProject; 566 | attributes = { 567 | LastUpgradeCheck = 0610; 568 | ORGANIZATIONNAME = Facebook; 569 | TargetAttributes = { 570 | 00E356ED1AD99517003FC87E = { 571 | CreatedOnToolsVersion = 6.2; 572 | TestTargetID = 13B07F861A680F5B00A75B9A; 573 | }; 574 | 2D02E47A1E0B4A5D006451C7 = { 575 | CreatedOnToolsVersion = 8.2.1; 576 | ProvisioningStyle = Automatic; 577 | }; 578 | 2D02E48F1E0B4A5D006451C7 = { 579 | CreatedOnToolsVersion = 8.2.1; 580 | ProvisioningStyle = Automatic; 581 | TestTargetID = 2D02E47A1E0B4A5D006451C7; 582 | }; 583 | }; 584 | }; 585 | buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "firebaseLocalCache" */; 586 | compatibilityVersion = "Xcode 3.2"; 587 | developmentRegion = English; 588 | hasScannedForEncodings = 0; 589 | knownRegions = ( 590 | en, 591 | Base, 592 | ); 593 | mainGroup = 83CBB9F61A601CBA00E9B192; 594 | productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */; 595 | projectDirPath = ""; 596 | projectReferences = ( 597 | { 598 | ProductGroup = 00C302A81ABCB8CE00DB3ED1 /* Products */; 599 | ProjectRef = 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */; 600 | }, 601 | { 602 | ProductGroup = 5E91572E1DD0AC6500FF2AA8 /* Products */; 603 | ProjectRef = 5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */; 604 | }, 605 | { 606 | ProductGroup = 00C302B61ABCB90400DB3ED1 /* Products */; 607 | ProjectRef = 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */; 608 | }, 609 | { 610 | ProductGroup = 00C302BC1ABCB91800DB3ED1 /* Products */; 611 | ProjectRef = 00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */; 612 | }, 613 | { 614 | ProductGroup = 78C398B11ACF4ADC00677621 /* Products */; 615 | ProjectRef = 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */; 616 | }, 617 | { 618 | ProductGroup = 00C302D41ABCB9D200DB3ED1 /* Products */; 619 | ProjectRef = 00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */; 620 | }, 621 | { 622 | ProductGroup = 139105B71AF99BAD00B5F7CC /* Products */; 623 | ProjectRef = 139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */; 624 | }, 625 | { 626 | ProductGroup = 832341B11AAA6A8300B99B32 /* Products */; 627 | ProjectRef = 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */; 628 | }, 629 | { 630 | ProductGroup = 00C302E01ABCB9EE00DB3ED1 /* Products */; 631 | ProjectRef = 00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */; 632 | }, 633 | { 634 | ProductGroup = 139FDEE71B06529A00C62182 /* Products */; 635 | ProjectRef = 139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */; 636 | }, 637 | { 638 | ProductGroup = 146834001AC3E56700842450 /* Products */; 639 | ProjectRef = 146833FF1AC3E56700842450 /* React.xcodeproj */; 640 | }, 641 | ); 642 | projectRoot = ""; 643 | targets = ( 644 | 13B07F861A680F5B00A75B9A /* firebaseLocalCache */, 645 | 00E356ED1AD99517003FC87E /* firebaseLocalCacheTests */, 646 | 2D02E47A1E0B4A5D006451C7 /* firebaseLocalCache-tvOS */, 647 | 2D02E48F1E0B4A5D006451C7 /* firebaseLocalCache-tvOSTests */, 648 | ); 649 | }; 650 | /* End PBXProject section */ 651 | 652 | /* Begin PBXReferenceProxy section */ 653 | 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */ = { 654 | isa = PBXReferenceProxy; 655 | fileType = archive.ar; 656 | path = libRCTActionSheet.a; 657 | remoteRef = 00C302AB1ABCB8CE00DB3ED1 /* PBXContainerItemProxy */; 658 | sourceTree = BUILT_PRODUCTS_DIR; 659 | }; 660 | 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */ = { 661 | isa = PBXReferenceProxy; 662 | fileType = archive.ar; 663 | path = libRCTGeolocation.a; 664 | remoteRef = 00C302B91ABCB90400DB3ED1 /* PBXContainerItemProxy */; 665 | sourceTree = BUILT_PRODUCTS_DIR; 666 | }; 667 | 00C302C01ABCB91800DB3ED1 /* libRCTImage.a */ = { 668 | isa = PBXReferenceProxy; 669 | fileType = archive.ar; 670 | path = libRCTImage.a; 671 | remoteRef = 00C302BF1ABCB91800DB3ED1 /* PBXContainerItemProxy */; 672 | sourceTree = BUILT_PRODUCTS_DIR; 673 | }; 674 | 00C302DC1ABCB9D200DB3ED1 /* libRCTNetwork.a */ = { 675 | isa = PBXReferenceProxy; 676 | fileType = archive.ar; 677 | path = libRCTNetwork.a; 678 | remoteRef = 00C302DB1ABCB9D200DB3ED1 /* PBXContainerItemProxy */; 679 | sourceTree = BUILT_PRODUCTS_DIR; 680 | }; 681 | 00C302E41ABCB9EE00DB3ED1 /* libRCTVibration.a */ = { 682 | isa = PBXReferenceProxy; 683 | fileType = archive.ar; 684 | path = libRCTVibration.a; 685 | remoteRef = 00C302E31ABCB9EE00DB3ED1 /* PBXContainerItemProxy */; 686 | sourceTree = BUILT_PRODUCTS_DIR; 687 | }; 688 | 139105C11AF99BAD00B5F7CC /* libRCTSettings.a */ = { 689 | isa = PBXReferenceProxy; 690 | fileType = archive.ar; 691 | path = libRCTSettings.a; 692 | remoteRef = 139105C01AF99BAD00B5F7CC /* PBXContainerItemProxy */; 693 | sourceTree = BUILT_PRODUCTS_DIR; 694 | }; 695 | 139FDEF41B06529B00C62182 /* libRCTWebSocket.a */ = { 696 | isa = PBXReferenceProxy; 697 | fileType = archive.ar; 698 | path = libRCTWebSocket.a; 699 | remoteRef = 139FDEF31B06529B00C62182 /* PBXContainerItemProxy */; 700 | sourceTree = BUILT_PRODUCTS_DIR; 701 | }; 702 | 146834041AC3E56700842450 /* libReact.a */ = { 703 | isa = PBXReferenceProxy; 704 | fileType = archive.ar; 705 | path = libReact.a; 706 | remoteRef = 146834031AC3E56700842450 /* PBXContainerItemProxy */; 707 | sourceTree = BUILT_PRODUCTS_DIR; 708 | }; 709 | 3DAD3E841DF850E9000B6D8A /* libRCTImage-tvOS.a */ = { 710 | isa = PBXReferenceProxy; 711 | fileType = archive.ar; 712 | path = "libRCTImage-tvOS.a"; 713 | remoteRef = 3DAD3E831DF850E9000B6D8A /* PBXContainerItemProxy */; 714 | sourceTree = BUILT_PRODUCTS_DIR; 715 | }; 716 | 3DAD3E881DF850E9000B6D8A /* libRCTLinking-tvOS.a */ = { 717 | isa = PBXReferenceProxy; 718 | fileType = archive.ar; 719 | path = "libRCTLinking-tvOS.a"; 720 | remoteRef = 3DAD3E871DF850E9000B6D8A /* PBXContainerItemProxy */; 721 | sourceTree = BUILT_PRODUCTS_DIR; 722 | }; 723 | 3DAD3E8C1DF850E9000B6D8A /* libRCTNetwork-tvOS.a */ = { 724 | isa = PBXReferenceProxy; 725 | fileType = archive.ar; 726 | path = "libRCTNetwork-tvOS.a"; 727 | remoteRef = 3DAD3E8B1DF850E9000B6D8A /* PBXContainerItemProxy */; 728 | sourceTree = BUILT_PRODUCTS_DIR; 729 | }; 730 | 3DAD3E901DF850E9000B6D8A /* libRCTSettings-tvOS.a */ = { 731 | isa = PBXReferenceProxy; 732 | fileType = archive.ar; 733 | path = "libRCTSettings-tvOS.a"; 734 | remoteRef = 3DAD3E8F1DF850E9000B6D8A /* PBXContainerItemProxy */; 735 | sourceTree = BUILT_PRODUCTS_DIR; 736 | }; 737 | 3DAD3E941DF850E9000B6D8A /* libRCTText-tvOS.a */ = { 738 | isa = PBXReferenceProxy; 739 | fileType = archive.ar; 740 | path = "libRCTText-tvOS.a"; 741 | remoteRef = 3DAD3E931DF850E9000B6D8A /* PBXContainerItemProxy */; 742 | sourceTree = BUILT_PRODUCTS_DIR; 743 | }; 744 | 3DAD3E991DF850E9000B6D8A /* libRCTWebSocket-tvOS.a */ = { 745 | isa = PBXReferenceProxy; 746 | fileType = archive.ar; 747 | path = "libRCTWebSocket-tvOS.a"; 748 | remoteRef = 3DAD3E981DF850E9000B6D8A /* PBXContainerItemProxy */; 749 | sourceTree = BUILT_PRODUCTS_DIR; 750 | }; 751 | 3DAD3EA31DF850E9000B6D8A /* libReact.a */ = { 752 | isa = PBXReferenceProxy; 753 | fileType = archive.ar; 754 | path = libReact.a; 755 | remoteRef = 3DAD3EA21DF850E9000B6D8A /* PBXContainerItemProxy */; 756 | sourceTree = BUILT_PRODUCTS_DIR; 757 | }; 758 | 3DAD3EA51DF850E9000B6D8A /* libyoga.a */ = { 759 | isa = PBXReferenceProxy; 760 | fileType = archive.ar; 761 | path = libyoga.a; 762 | remoteRef = 3DAD3EA41DF850E9000B6D8A /* PBXContainerItemProxy */; 763 | sourceTree = BUILT_PRODUCTS_DIR; 764 | }; 765 | 3DAD3EA71DF850E9000B6D8A /* libyoga.a */ = { 766 | isa = PBXReferenceProxy; 767 | fileType = archive.ar; 768 | path = libyoga.a; 769 | remoteRef = 3DAD3EA61DF850E9000B6D8A /* PBXContainerItemProxy */; 770 | sourceTree = BUILT_PRODUCTS_DIR; 771 | }; 772 | 3DAD3EA91DF850E9000B6D8A /* libcxxreact.a */ = { 773 | isa = PBXReferenceProxy; 774 | fileType = archive.ar; 775 | path = libcxxreact.a; 776 | remoteRef = 3DAD3EA81DF850E9000B6D8A /* PBXContainerItemProxy */; 777 | sourceTree = BUILT_PRODUCTS_DIR; 778 | }; 779 | 3DAD3EAB1DF850E9000B6D8A /* libcxxreact.a */ = { 780 | isa = PBXReferenceProxy; 781 | fileType = archive.ar; 782 | path = libcxxreact.a; 783 | remoteRef = 3DAD3EAA1DF850E9000B6D8A /* PBXContainerItemProxy */; 784 | sourceTree = BUILT_PRODUCTS_DIR; 785 | }; 786 | 3DAD3EAD1DF850E9000B6D8A /* libjschelpers.a */ = { 787 | isa = PBXReferenceProxy; 788 | fileType = archive.ar; 789 | path = libjschelpers.a; 790 | remoteRef = 3DAD3EAC1DF850E9000B6D8A /* PBXContainerItemProxy */; 791 | sourceTree = BUILT_PRODUCTS_DIR; 792 | }; 793 | 3DAD3EAF1DF850E9000B6D8A /* libjschelpers.a */ = { 794 | isa = PBXReferenceProxy; 795 | fileType = archive.ar; 796 | path = libjschelpers.a; 797 | remoteRef = 3DAD3EAE1DF850E9000B6D8A /* PBXContainerItemProxy */; 798 | sourceTree = BUILT_PRODUCTS_DIR; 799 | }; 800 | 5E9157331DD0AC6500FF2AA8 /* libRCTAnimation.a */ = { 801 | isa = PBXReferenceProxy; 802 | fileType = archive.ar; 803 | path = libRCTAnimation.a; 804 | remoteRef = 5E9157321DD0AC6500FF2AA8 /* PBXContainerItemProxy */; 805 | sourceTree = BUILT_PRODUCTS_DIR; 806 | }; 807 | 5E9157351DD0AC6500FF2AA8 /* libRCTAnimation-tvOS.a */ = { 808 | isa = PBXReferenceProxy; 809 | fileType = archive.ar; 810 | path = "libRCTAnimation-tvOS.a"; 811 | remoteRef = 5E9157341DD0AC6500FF2AA8 /* PBXContainerItemProxy */; 812 | sourceTree = BUILT_PRODUCTS_DIR; 813 | }; 814 | 78C398B91ACF4ADC00677621 /* libRCTLinking.a */ = { 815 | isa = PBXReferenceProxy; 816 | fileType = archive.ar; 817 | path = libRCTLinking.a; 818 | remoteRef = 78C398B81ACF4ADC00677621 /* PBXContainerItemProxy */; 819 | sourceTree = BUILT_PRODUCTS_DIR; 820 | }; 821 | 832341B51AAA6A8300B99B32 /* libRCTText.a */ = { 822 | isa = PBXReferenceProxy; 823 | fileType = archive.ar; 824 | path = libRCTText.a; 825 | remoteRef = 832341B41AAA6A8300B99B32 /* PBXContainerItemProxy */; 826 | sourceTree = BUILT_PRODUCTS_DIR; 827 | }; 828 | /* End PBXReferenceProxy section */ 829 | 830 | /* Begin PBXResourcesBuildPhase section */ 831 | 00E356EC1AD99517003FC87E /* Resources */ = { 832 | isa = PBXResourcesBuildPhase; 833 | buildActionMask = 2147483647; 834 | files = ( 835 | ); 836 | runOnlyForDeploymentPostprocessing = 0; 837 | }; 838 | 13B07F8E1A680F5B00A75B9A /* Resources */ = { 839 | isa = PBXResourcesBuildPhase; 840 | buildActionMask = 2147483647; 841 | files = ( 842 | 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, 843 | 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */, 844 | ); 845 | runOnlyForDeploymentPostprocessing = 0; 846 | }; 847 | 2D02E4791E0B4A5D006451C7 /* Resources */ = { 848 | isa = PBXResourcesBuildPhase; 849 | buildActionMask = 2147483647; 850 | files = ( 851 | 2D02E4BD1E0B4A84006451C7 /* Images.xcassets in Resources */, 852 | ); 853 | runOnlyForDeploymentPostprocessing = 0; 854 | }; 855 | 2D02E48E1E0B4A5D006451C7 /* Resources */ = { 856 | isa = PBXResourcesBuildPhase; 857 | buildActionMask = 2147483647; 858 | files = ( 859 | ); 860 | runOnlyForDeploymentPostprocessing = 0; 861 | }; 862 | /* End PBXResourcesBuildPhase section */ 863 | 864 | /* Begin PBXShellScriptBuildPhase section */ 865 | 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */ = { 866 | isa = PBXShellScriptBuildPhase; 867 | buildActionMask = 2147483647; 868 | files = ( 869 | ); 870 | inputPaths = ( 871 | ); 872 | name = "Bundle React Native code and images"; 873 | outputPaths = ( 874 | ); 875 | runOnlyForDeploymentPostprocessing = 0; 876 | shellPath = /bin/sh; 877 | shellScript = "export NODE_BINARY=node\n../node_modules/react-native/packager/react-native-xcode.sh"; 878 | }; 879 | 2D02E4CB1E0B4B27006451C7 /* Bundle React Native Code And Images */ = { 880 | isa = PBXShellScriptBuildPhase; 881 | buildActionMask = 2147483647; 882 | files = ( 883 | ); 884 | inputPaths = ( 885 | ); 886 | name = "Bundle React Native Code And Images"; 887 | outputPaths = ( 888 | ); 889 | runOnlyForDeploymentPostprocessing = 0; 890 | shellPath = /bin/sh; 891 | shellScript = "export NODE_BINARY=node\n../node_modules/react-native/packager/react-native-xcode.sh"; 892 | }; 893 | /* End PBXShellScriptBuildPhase section */ 894 | 895 | /* Begin PBXSourcesBuildPhase section */ 896 | 00E356EA1AD99517003FC87E /* Sources */ = { 897 | isa = PBXSourcesBuildPhase; 898 | buildActionMask = 2147483647; 899 | files = ( 900 | 00E356F31AD99517003FC87E /* firebaseLocalCacheTests.m in Sources */, 901 | ); 902 | runOnlyForDeploymentPostprocessing = 0; 903 | }; 904 | 13B07F871A680F5B00A75B9A /* Sources */ = { 905 | isa = PBXSourcesBuildPhase; 906 | buildActionMask = 2147483647; 907 | files = ( 908 | 13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */, 909 | 13B07FC11A68108700A75B9A /* main.m in Sources */, 910 | ); 911 | runOnlyForDeploymentPostprocessing = 0; 912 | }; 913 | 2D02E4771E0B4A5D006451C7 /* Sources */ = { 914 | isa = PBXSourcesBuildPhase; 915 | buildActionMask = 2147483647; 916 | files = ( 917 | 2D02E4BF1E0B4AB3006451C7 /* main.m in Sources */, 918 | 2D02E4BC1E0B4A80006451C7 /* AppDelegate.m in Sources */, 919 | ); 920 | runOnlyForDeploymentPostprocessing = 0; 921 | }; 922 | 2D02E48C1E0B4A5D006451C7 /* Sources */ = { 923 | isa = PBXSourcesBuildPhase; 924 | buildActionMask = 2147483647; 925 | files = ( 926 | 2DCD954D1E0B4F2C00145EB5 /* firebaseLocalCacheTests.m in Sources */, 927 | ); 928 | runOnlyForDeploymentPostprocessing = 0; 929 | }; 930 | /* End PBXSourcesBuildPhase section */ 931 | 932 | /* Begin PBXTargetDependency section */ 933 | 00E356F51AD99517003FC87E /* PBXTargetDependency */ = { 934 | isa = PBXTargetDependency; 935 | target = 13B07F861A680F5B00A75B9A /* firebaseLocalCache */; 936 | targetProxy = 00E356F41AD99517003FC87E /* PBXContainerItemProxy */; 937 | }; 938 | 2D02E4921E0B4A5D006451C7 /* PBXTargetDependency */ = { 939 | isa = PBXTargetDependency; 940 | target = 2D02E47A1E0B4A5D006451C7 /* firebaseLocalCache-tvOS */; 941 | targetProxy = 2D02E4911E0B4A5D006451C7 /* PBXContainerItemProxy */; 942 | }; 943 | /* End PBXTargetDependency section */ 944 | 945 | /* Begin PBXVariantGroup section */ 946 | 13B07FB11A68108700A75B9A /* LaunchScreen.xib */ = { 947 | isa = PBXVariantGroup; 948 | children = ( 949 | 13B07FB21A68108700A75B9A /* Base */, 950 | ); 951 | name = LaunchScreen.xib; 952 | path = firebaseLocalCache; 953 | sourceTree = ""; 954 | }; 955 | /* End PBXVariantGroup section */ 956 | 957 | /* Begin XCBuildConfiguration section */ 958 | 00E356F61AD99517003FC87E /* Debug */ = { 959 | isa = XCBuildConfiguration; 960 | buildSettings = { 961 | BUNDLE_LOADER = "$(TEST_HOST)"; 962 | GCC_PREPROCESSOR_DEFINITIONS = ( 963 | "DEBUG=1", 964 | "$(inherited)", 965 | ); 966 | INFOPLIST_FILE = firebaseLocalCacheTests/Info.plist; 967 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 968 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 969 | OTHER_LDFLAGS = ( 970 | "-ObjC", 971 | "-lc++", 972 | ); 973 | PRODUCT_NAME = "$(TARGET_NAME)"; 974 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/firebaseLocalCache.app/firebaseLocalCache"; 975 | }; 976 | name = Debug; 977 | }; 978 | 00E356F71AD99517003FC87E /* Release */ = { 979 | isa = XCBuildConfiguration; 980 | buildSettings = { 981 | BUNDLE_LOADER = "$(TEST_HOST)"; 982 | COPY_PHASE_STRIP = NO; 983 | INFOPLIST_FILE = firebaseLocalCacheTests/Info.plist; 984 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 985 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 986 | OTHER_LDFLAGS = ( 987 | "-ObjC", 988 | "-lc++", 989 | ); 990 | PRODUCT_NAME = "$(TARGET_NAME)"; 991 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/firebaseLocalCache.app/firebaseLocalCache"; 992 | }; 993 | name = Release; 994 | }; 995 | 13B07F941A680F5B00A75B9A /* Debug */ = { 996 | isa = XCBuildConfiguration; 997 | buildSettings = { 998 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 999 | CURRENT_PROJECT_VERSION = 1; 1000 | DEAD_CODE_STRIPPING = NO; 1001 | INFOPLIST_FILE = firebaseLocalCache/Info.plist; 1002 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 1003 | OTHER_LDFLAGS = ( 1004 | "$(inherited)", 1005 | "-ObjC", 1006 | "-lc++", 1007 | ); 1008 | PRODUCT_NAME = firebaseLocalCache; 1009 | VERSIONING_SYSTEM = "apple-generic"; 1010 | }; 1011 | name = Debug; 1012 | }; 1013 | 13B07F951A680F5B00A75B9A /* Release */ = { 1014 | isa = XCBuildConfiguration; 1015 | buildSettings = { 1016 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 1017 | CURRENT_PROJECT_VERSION = 1; 1018 | INFOPLIST_FILE = firebaseLocalCache/Info.plist; 1019 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 1020 | OTHER_LDFLAGS = ( 1021 | "$(inherited)", 1022 | "-ObjC", 1023 | "-lc++", 1024 | ); 1025 | PRODUCT_NAME = firebaseLocalCache; 1026 | VERSIONING_SYSTEM = "apple-generic"; 1027 | }; 1028 | name = Release; 1029 | }; 1030 | 2D02E4971E0B4A5E006451C7 /* Debug */ = { 1031 | isa = XCBuildConfiguration; 1032 | buildSettings = { 1033 | ASSETCATALOG_COMPILER_APPICON_NAME = "App Icon & Top Shelf Image"; 1034 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 1035 | CLANG_ANALYZER_NONNULL = YES; 1036 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 1037 | CLANG_WARN_INFINITE_RECURSION = YES; 1038 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 1039 | DEBUG_INFORMATION_FORMAT = dwarf; 1040 | ENABLE_TESTABILITY = YES; 1041 | GCC_NO_COMMON_BLOCKS = YES; 1042 | INFOPLIST_FILE = "firebaseLocalCache-tvOS/Info.plist"; 1043 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 1044 | OTHER_LDFLAGS = ( 1045 | "-ObjC", 1046 | "-lc++", 1047 | ); 1048 | PRODUCT_BUNDLE_IDENTIFIER = "com.facebook.REACT.firebaseLocalCache-tvOS"; 1049 | PRODUCT_NAME = "$(TARGET_NAME)"; 1050 | SDKROOT = appletvos; 1051 | TARGETED_DEVICE_FAMILY = 3; 1052 | TVOS_DEPLOYMENT_TARGET = 9.2; 1053 | }; 1054 | name = Debug; 1055 | }; 1056 | 2D02E4981E0B4A5E006451C7 /* Release */ = { 1057 | isa = XCBuildConfiguration; 1058 | buildSettings = { 1059 | ASSETCATALOG_COMPILER_APPICON_NAME = "App Icon & Top Shelf Image"; 1060 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 1061 | CLANG_ANALYZER_NONNULL = YES; 1062 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 1063 | CLANG_WARN_INFINITE_RECURSION = YES; 1064 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 1065 | COPY_PHASE_STRIP = NO; 1066 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 1067 | GCC_NO_COMMON_BLOCKS = YES; 1068 | INFOPLIST_FILE = "firebaseLocalCache-tvOS/Info.plist"; 1069 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 1070 | OTHER_LDFLAGS = ( 1071 | "-ObjC", 1072 | "-lc++", 1073 | ); 1074 | PRODUCT_BUNDLE_IDENTIFIER = "com.facebook.REACT.firebaseLocalCache-tvOS"; 1075 | PRODUCT_NAME = "$(TARGET_NAME)"; 1076 | SDKROOT = appletvos; 1077 | TARGETED_DEVICE_FAMILY = 3; 1078 | TVOS_DEPLOYMENT_TARGET = 9.2; 1079 | }; 1080 | name = Release; 1081 | }; 1082 | 2D02E4991E0B4A5E006451C7 /* Debug */ = { 1083 | isa = XCBuildConfiguration; 1084 | buildSettings = { 1085 | BUNDLE_LOADER = "$(TEST_HOST)"; 1086 | CLANG_ANALYZER_NONNULL = YES; 1087 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 1088 | CLANG_WARN_INFINITE_RECURSION = YES; 1089 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 1090 | DEBUG_INFORMATION_FORMAT = dwarf; 1091 | ENABLE_TESTABILITY = YES; 1092 | GCC_NO_COMMON_BLOCKS = YES; 1093 | INFOPLIST_FILE = "firebaseLocalCache-tvOSTests/Info.plist"; 1094 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 1095 | PRODUCT_BUNDLE_IDENTIFIER = "com.facebook.REACT.firebaseLocalCache-tvOSTests"; 1096 | PRODUCT_NAME = "$(TARGET_NAME)"; 1097 | SDKROOT = appletvos; 1098 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/firebaseLocalCache-tvOS.app/firebaseLocalCache-tvOS"; 1099 | TVOS_DEPLOYMENT_TARGET = 10.1; 1100 | }; 1101 | name = Debug; 1102 | }; 1103 | 2D02E49A1E0B4A5E006451C7 /* Release */ = { 1104 | isa = XCBuildConfiguration; 1105 | buildSettings = { 1106 | BUNDLE_LOADER = "$(TEST_HOST)"; 1107 | CLANG_ANALYZER_NONNULL = YES; 1108 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 1109 | CLANG_WARN_INFINITE_RECURSION = YES; 1110 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 1111 | COPY_PHASE_STRIP = NO; 1112 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 1113 | GCC_NO_COMMON_BLOCKS = YES; 1114 | INFOPLIST_FILE = "firebaseLocalCache-tvOSTests/Info.plist"; 1115 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 1116 | PRODUCT_BUNDLE_IDENTIFIER = "com.facebook.REACT.firebaseLocalCache-tvOSTests"; 1117 | PRODUCT_NAME = "$(TARGET_NAME)"; 1118 | SDKROOT = appletvos; 1119 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/firebaseLocalCache-tvOS.app/firebaseLocalCache-tvOS"; 1120 | TVOS_DEPLOYMENT_TARGET = 10.1; 1121 | }; 1122 | name = Release; 1123 | }; 1124 | 83CBBA201A601CBA00E9B192 /* Debug */ = { 1125 | isa = XCBuildConfiguration; 1126 | buildSettings = { 1127 | ALWAYS_SEARCH_USER_PATHS = NO; 1128 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 1129 | CLANG_CXX_LIBRARY = "libc++"; 1130 | CLANG_ENABLE_MODULES = YES; 1131 | CLANG_ENABLE_OBJC_ARC = YES; 1132 | CLANG_WARN_BOOL_CONVERSION = YES; 1133 | CLANG_WARN_CONSTANT_CONVERSION = YES; 1134 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 1135 | CLANG_WARN_EMPTY_BODY = YES; 1136 | CLANG_WARN_ENUM_CONVERSION = YES; 1137 | CLANG_WARN_INT_CONVERSION = YES; 1138 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 1139 | CLANG_WARN_UNREACHABLE_CODE = YES; 1140 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 1141 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 1142 | COPY_PHASE_STRIP = NO; 1143 | ENABLE_STRICT_OBJC_MSGSEND = YES; 1144 | GCC_C_LANGUAGE_STANDARD = gnu99; 1145 | GCC_DYNAMIC_NO_PIC = NO; 1146 | GCC_OPTIMIZATION_LEVEL = 0; 1147 | GCC_PREPROCESSOR_DEFINITIONS = ( 1148 | "DEBUG=1", 1149 | "$(inherited)", 1150 | ); 1151 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 1152 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 1153 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 1154 | GCC_WARN_UNDECLARED_SELECTOR = YES; 1155 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 1156 | GCC_WARN_UNUSED_FUNCTION = YES; 1157 | GCC_WARN_UNUSED_VARIABLE = YES; 1158 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 1159 | MTL_ENABLE_DEBUG_INFO = YES; 1160 | ONLY_ACTIVE_ARCH = YES; 1161 | SDKROOT = iphoneos; 1162 | }; 1163 | name = Debug; 1164 | }; 1165 | 83CBBA211A601CBA00E9B192 /* Release */ = { 1166 | isa = XCBuildConfiguration; 1167 | buildSettings = { 1168 | ALWAYS_SEARCH_USER_PATHS = NO; 1169 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 1170 | CLANG_CXX_LIBRARY = "libc++"; 1171 | CLANG_ENABLE_MODULES = YES; 1172 | CLANG_ENABLE_OBJC_ARC = YES; 1173 | CLANG_WARN_BOOL_CONVERSION = YES; 1174 | CLANG_WARN_CONSTANT_CONVERSION = YES; 1175 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 1176 | CLANG_WARN_EMPTY_BODY = YES; 1177 | CLANG_WARN_ENUM_CONVERSION = YES; 1178 | CLANG_WARN_INT_CONVERSION = YES; 1179 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 1180 | CLANG_WARN_UNREACHABLE_CODE = YES; 1181 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 1182 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 1183 | COPY_PHASE_STRIP = YES; 1184 | ENABLE_NS_ASSERTIONS = NO; 1185 | ENABLE_STRICT_OBJC_MSGSEND = YES; 1186 | GCC_C_LANGUAGE_STANDARD = gnu99; 1187 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 1188 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 1189 | GCC_WARN_UNDECLARED_SELECTOR = YES; 1190 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 1191 | GCC_WARN_UNUSED_FUNCTION = YES; 1192 | GCC_WARN_UNUSED_VARIABLE = YES; 1193 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 1194 | MTL_ENABLE_DEBUG_INFO = NO; 1195 | SDKROOT = iphoneos; 1196 | VALIDATE_PRODUCT = YES; 1197 | }; 1198 | name = Release; 1199 | }; 1200 | /* End XCBuildConfiguration section */ 1201 | 1202 | /* Begin XCConfigurationList section */ 1203 | 00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "firebaseLocalCacheTests" */ = { 1204 | isa = XCConfigurationList; 1205 | buildConfigurations = ( 1206 | 00E356F61AD99517003FC87E /* Debug */, 1207 | 00E356F71AD99517003FC87E /* Release */, 1208 | ); 1209 | defaultConfigurationIsVisible = 0; 1210 | defaultConfigurationName = Release; 1211 | }; 1212 | 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "firebaseLocalCache" */ = { 1213 | isa = XCConfigurationList; 1214 | buildConfigurations = ( 1215 | 13B07F941A680F5B00A75B9A /* Debug */, 1216 | 13B07F951A680F5B00A75B9A /* Release */, 1217 | ); 1218 | defaultConfigurationIsVisible = 0; 1219 | defaultConfigurationName = Release; 1220 | }; 1221 | 2D02E4BA1E0B4A5E006451C7 /* Build configuration list for PBXNativeTarget "firebaseLocalCache-tvOS" */ = { 1222 | isa = XCConfigurationList; 1223 | buildConfigurations = ( 1224 | 2D02E4971E0B4A5E006451C7 /* Debug */, 1225 | 2D02E4981E0B4A5E006451C7 /* Release */, 1226 | ); 1227 | defaultConfigurationIsVisible = 0; 1228 | defaultConfigurationName = Release; 1229 | }; 1230 | 2D02E4BB1E0B4A5E006451C7 /* Build configuration list for PBXNativeTarget "firebaseLocalCache-tvOSTests" */ = { 1231 | isa = XCConfigurationList; 1232 | buildConfigurations = ( 1233 | 2D02E4991E0B4A5E006451C7 /* Debug */, 1234 | 2D02E49A1E0B4A5E006451C7 /* Release */, 1235 | ); 1236 | defaultConfigurationIsVisible = 0; 1237 | defaultConfigurationName = Release; 1238 | }; 1239 | 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "firebaseLocalCache" */ = { 1240 | isa = XCConfigurationList; 1241 | buildConfigurations = ( 1242 | 83CBBA201A601CBA00E9B192 /* Debug */, 1243 | 83CBBA211A601CBA00E9B192 /* Release */, 1244 | ); 1245 | defaultConfigurationIsVisible = 0; 1246 | defaultConfigurationName = Release; 1247 | }; 1248 | /* End XCConfigurationList section */ 1249 | }; 1250 | rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */; 1251 | } 1252 | -------------------------------------------------------------------------------- /Example/ios/firebaseLocalCache.xcodeproj/xcshareddata/xcschemes/firebaseLocalCache-tvOS.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 43 | 49 | 50 | 51 | 52 | 53 | 58 | 59 | 61 | 67 | 68 | 69 | 70 | 71 | 77 | 78 | 79 | 80 | 81 | 82 | 92 | 94 | 100 | 101 | 102 | 103 | 104 | 105 | 111 | 113 | 119 | 120 | 121 | 122 | 124 | 125 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /Example/ios/firebaseLocalCache.xcodeproj/xcshareddata/xcschemes/firebaseLocalCache.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 43 | 49 | 50 | 51 | 52 | 53 | 58 | 59 | 61 | 67 | 68 | 69 | 70 | 71 | 77 | 78 | 79 | 80 | 81 | 82 | 92 | 94 | 100 | 101 | 102 | 103 | 104 | 105 | 111 | 113 | 119 | 120 | 121 | 122 | 124 | 125 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /Example/ios/firebaseLocalCache/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | 12 | @interface AppDelegate : UIResponder 13 | 14 | @property (nonatomic, strong) UIWindow *window; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Example/ios/firebaseLocalCache/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import "AppDelegate.h" 11 | 12 | #import 13 | #import 14 | 15 | @implementation AppDelegate 16 | 17 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 18 | { 19 | NSURL *jsCodeLocation; 20 | 21 | jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil]; 22 | 23 | RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation 24 | moduleName:@"firebaseLocalCache" 25 | initialProperties:nil 26 | launchOptions:launchOptions]; 27 | rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; 28 | 29 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 30 | UIViewController *rootViewController = [UIViewController new]; 31 | rootViewController.view = rootView; 32 | self.window.rootViewController = rootViewController; 33 | [self.window makeKeyAndVisible]; 34 | return YES; 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /Example/ios/firebaseLocalCache/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Example/ios/firebaseLocalCache/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Example/ios/firebaseLocalCache/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | firebaseLocalCache 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSRequiresIPhoneOS 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UIViewControllerBasedStatusBarAppearance 40 | 41 | NSLocationWhenInUseUsageDescription 42 | 43 | NSAppTransportSecurity 44 | 45 | 46 | NSExceptionDomains 47 | 48 | localhost 49 | 50 | NSExceptionAllowsInsecureHTTPLoads 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /Example/ios/firebaseLocalCache/main.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | 12 | #import "AppDelegate.h" 13 | 14 | int main(int argc, char * argv[]) { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Example/ios/firebaseLocalCacheTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Example/ios/firebaseLocalCacheTests/firebaseLocalCacheTests.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | #import 12 | 13 | #import 14 | #import 15 | 16 | #define TIMEOUT_SECONDS 600 17 | #define TEXT_TO_LOOK_FOR @"Welcome to React Native!" 18 | 19 | @interface firebaseLocalCacheTests : XCTestCase 20 | 21 | @end 22 | 23 | @implementation firebaseLocalCacheTests 24 | 25 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test 26 | { 27 | if (test(view)) { 28 | return YES; 29 | } 30 | for (UIView *subview in [view subviews]) { 31 | if ([self findSubviewInView:subview matching:test]) { 32 | return YES; 33 | } 34 | } 35 | return NO; 36 | } 37 | 38 | - (void)testRendersWelcomeScreen 39 | { 40 | UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; 41 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; 42 | BOOL foundElement = NO; 43 | 44 | __block NSString *redboxError = nil; 45 | RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { 46 | if (level >= RCTLogLevelError) { 47 | redboxError = message; 48 | } 49 | }); 50 | 51 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { 52 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 53 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 54 | 55 | foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) { 56 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { 57 | return YES; 58 | } 59 | return NO; 60 | }]; 61 | } 62 | 63 | RCTSetLogFunction(RCTDefaultLogFunction); 64 | 65 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); 66 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); 67 | } 68 | 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /Example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "firebaseLocalCache", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "start": "node node_modules/react-native/local-cli/cli.js start", 7 | "test": "jest" 8 | }, 9 | "dependencies": { 10 | "firebase": "^3.7.5", 11 | "react": "16.0.0-alpha.6", 12 | "react-native": "0.43.1", 13 | "react-native-firebase-local-cache": "^0.4.0", 14 | "react-navigation": "git+https://github.com/react-community/react-navigation.git#297470099df37075aace5abdffa73559c3a3392b" 15 | }, 16 | "devDependencies": { 17 | "babel-jest": "19.0.0", 18 | "babel-preset-react-native": "1.9.1", 19 | "jest": "19.0.2", 20 | "react-test-renderer": "16.0.0-alpha.6" 21 | }, 22 | "jest": { 23 | "preset": "react-native" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/cuttingsoup/react-native-firebase-local-cache.svg?branch=master)](https://travis-ci.org/cuttingsoup/react-native-firebase-local-cache) [![Coverage Status](https://coveralls.io/repos/github/cuttingsoup/react-native-firebase-local-cache/badge.svg?branch=master)](https://coveralls.io/github/cuttingsoup/react-native-firebase-local-cache?branch=master) 2 | 3 | # react-native-firebase-local-cache 4 | A simple wrapper to add local caching of data to Firebase `on(...)` and `once(...)` listeners, useful for improving the apparent load time of screens/pages in your app. 5 | 6 | ## Updated API 7 | 8 | The exported methods from the module have changed slightly recently with the addition of support for `child_...ed` events and an equivalent to `once(...)`. The exports are: 9 | 10 | ### `'value'` Events 11 | 12 | `onValue(dbRef, snapCallback, processedCallback, cancelCallbackOrContext, context)` 13 | 14 | `offValue(dbRef)` 15 | 16 | ### `'child_added'` Events 17 | 18 | `onChildAdded(dbRef, fromCacheCallback, newDataArrivingCallback, snapCallback, cancelCallbackOrContext, context)` 19 | 20 | `offChildAdded(dbRef, dataToCache)` 21 | 22 | ### Other Child Events 23 | 24 | `onChildRemoved(dbRef, callback, cancelCallbackOrContext, context)` 25 | 26 | `onChildChanged(dbRef, callback, cancelCallbackOrContext, context)` 27 | 28 | `onChildMoved(dbRef, callback, cancelCallbackOrContext, context)` 29 | 30 | ### Once/Twice `'value'` Events 31 | 32 | `twice(dbRef, snapCallback, processedCallback, cancelCallbackOrContext, context)` 33 | 34 | ### Cache Control 35 | 36 | `clearCacheForRef(dbRef)` 37 | 38 | `clearCache()` 39 | 40 | ## Simple Use Case - `onValue` 41 | 42 | `onValue(dbRef, snapCallback, processedCallback, cancelCallbackOrContext, context)` 43 | 44 | In the simplest example, say displaying a users name and email. Previously you could do the following: 45 | 46 | ```javascript 47 | this.userRef.on('value', function(snap) { 48 | this.setState({ 49 | name: snap.val().name, 50 | email: snap.val().email 51 | }); 52 | },this); 53 | ``` 54 | 55 | The equivalent using this module would use `onValue(dbRef, snapCallback, processedCallback, cancelCallbackOrContext, context)`: 56 | 57 | ```javascript 58 | import * as cachedListener from 'react-native-firebase-local-cache'; 59 | 60 | ... 61 | 62 | cachedListener.onValue(this.userRef, function(snap) { 63 | return { 64 | name: snap.val().name, 65 | email: snap.val().email 66 | }); 67 | }, this.setState, this); 68 | ``` 69 | 70 | There is a little bit of trickiness going on here, but essentially the return value of `snapCallback` is cached, then passed as an argument to the `processedCallback`. The next time the listener is set up, `processedCallback` (in this case `this.setState`) will be called with the cached data immediately. When fresh snapshots arrive from the server they will be processed through both callbacks. 71 | 72 | So why not cache the `snapshot` directly? It is actually a pretty complex object that can't be stringified easily, it makes more sense to just process the snapshot and save that. Contributions always welcome though! 73 | 74 | Another slightly more complex example, say you have a list showing chat rooms a user is subscribed to, you might use the following code: 75 | 76 | ```javascript 77 | this.userRoomsRef.on('value', function(snap) { 78 | var rooms = []; 79 | 80 | snap.forEach((child) => { 81 | rooms.push({ 82 | roomName: child.val().name, 83 | _key: child.key 84 | }); 85 | }); 86 | 87 | this.setState({ 88 | dataSource: this.state.dataSource.cloneWithRows(rooms)) 89 | }); 90 | },this); 91 | ``` 92 | 93 | Again, until any data has been loaded, the list will remain empty. The equivalent code to cache this list for subsequent loads would be: 94 | 95 | ```javascript 96 | import * as cachedListener from 'react-native-firebase-local-cache'; 97 | 98 | ... 99 | 100 | 101 | cachedListener.onValue(this.userRoomsRef, function(snap) { 102 | var rooms = []; 103 | 104 | snap.forEach((child) => { 105 | rooms.push({ 106 | roomName: child.val().name, 107 | _key: child.key 108 | }); 109 | }); 110 | 111 | return rooms; 112 | }, function(rooms) { 113 | this.setState({ 114 | dataSource: this.state.dataSource.cloneWithRows(rooms)) 115 | }); 116 | },this); 117 | ``` 118 | 119 | The first callback does any processing of new data required and returns a __`JSON.stringify-able`__ object that can be cached. (_Note: objects are only committed to the cache when the corresponding `cachedListener.off(...)` method is called._) 120 | 121 | The second callback is passed either the freshly processed new data, or when first started, the cached data. 122 | 123 | A cancelCallback and/or context can optionally be passed as well. 124 | 125 | ## Multiple Listeners - `onValue` 126 | 127 | If you have multiple listeners attached to the same location, it is possible that they will overwrite each other, here is a very contrived example: 128 | 129 | On one screen: 130 | 131 | ```javascript 132 | this.userRef = firebase.database().ref(`users/${this.userId}`); 133 | 134 | cachedListener.onValue(this.userRef, function(snap) { 135 | return { 136 | name: snap.val().name, 137 | email: snap.val().email 138 | }); 139 | }, this.setState, this); 140 | ``` 141 | 142 | And on another: 143 | 144 | ```javascript 145 | this.userRef = firebase.database().ref(`users/${this.userId}`); 146 | 147 | cachedListener.onValue(this.userRef, function(snap) { 148 | return { 149 | name: snap.val().name, 150 | email: snap.val().email, 151 | age: snap.val().age 152 | }); 153 | }, function(user) { 154 | this.setState(user); 155 | this._doSomethingWithEmail(user.email); 156 | }, this); 157 | ``` 158 | 159 | When the first case runs, it will remove the `age` from the cache as it is not present in the returned data. 160 | 161 | One solution is to use a helper method that will use a single method to process the snapshot, and save everything you require: 162 | 163 | ```javascript 164 | const usersRef = firebase.database().ref('users'); 165 | 166 | ... 167 | 168 | export function createCachedUserListener(userId, callback, errorCallback, context) { 169 | cachedListener.onValue(usersRef.child(userId), function(snapshot) { 170 | //Process the snapshot to get any data that might be required. 171 | return { 172 | name: snap.val().name, 173 | email: snap.val().email, 174 | age: snap.val().age 175 | }; 176 | }, callback, errorCallback, context); 177 | } 178 | ``` 179 | 180 | On your original files, just use the data that is required: 181 | 182 | ```javascript 183 | Helper.createCachedUserListener(this.userId, function(user) { 184 | this.setState(user); 185 | this._doSomethingWithEmail(user.email); 186 | }, this); 187 | ``` 188 | 189 | You'll still need to call the off method to commit the data to the cache, whether you do this in a helper method or by calling it directly is up to you. 190 | 191 | ## Simple Use Case - `twice` 192 | 193 | This is a wrapper around the firebase `once` method and operates in a very similar way to the `onValue` method listed above. The key differences are: 194 | 195 | * Just like `once`, it will only wait for one new piece of data to come from the server, then it will stop listening and disconnect. 196 | * `snapCallback` will only be called once when the new data arrives, `processedCallback` will be called twice - once with cached data, once with new data. 197 | * Data is cached as soon as it is returned from the snapCallback, rather than when the `off` method is called. (Since you don't need to call it...) 198 | * It is cached separately to the `onValue` data. 199 | 200 | ## Simple Use Case - `onChildAdded` 201 | 202 | The flow of data through the `onChildAdded` method is somewhat different , but this is reflective of the common use cases. 203 | 204 | ### `onChildAdded(dbRef, fromCacheCallback, newDataArrivingCallback, snapCallback, cancelCallbackOrContext, context)` 205 | 206 | Create an 'child_added' on listener that will first return any cached data saved by a call to offChildAdded. When fresh data arrives, newDataArrivingCallback will be called once, followed by the standard snap callback. From this point on only the snapCallback will be called. 207 | 208 | **Parameters** 209 | 210 | **dbRef**: `firebase.database.Reference`, Firebase database reference to listen at. 211 | 212 | **fromCacheCallback**: `*`, Callback that will be called with cached data if any is available. 213 | 214 | **newDataArrivingCallback**: `*`, Callback called immediately before fresh data starts arriving. 215 | 216 | **snapCallback**: `*`, Callback called when new data snapshots arrive from the server. 217 | 218 | **cancelCallbackOrContext**: `*`, Optional callback that will be called in the case of an error, e.g. forbidden. 219 | 220 | **context**: `*`, Optional context that will be bound to `this` in callbacks. 221 | 222 | **Returns**: `Promise`, Resolves when the cache has been read and listener attached to DB ref. 223 | 224 | ### Example App Demo 225 | 226 | The following is from the example app: 227 | 228 | ```javascript 229 | _startCachedListener() { 230 | cachedListener.onChildAdded(this.messagesRef, function(cached){ 231 | // Receiving cached list of messages: 232 | this.setState({ 233 | dataSource: this.state.dataSource.cloneWithRows(cached), 234 | }); 235 | }, function() { 236 | //Clean up messages list (not required but this is where you would do it if it was) 237 | this.messages = []; 238 | }, function(snapshot) { 239 | //New snapshot available. 240 | this.messages.push(this._messageFromSnapshot(snapshot)); 241 | 242 | this.setState({ 243 | dataSource: this.state.dataSource.cloneWithRows(this.messages), 244 | }); 245 | },this); 246 | } 247 | 248 | _stopCachedListener() { 249 | //Cache the top two messages. Alternatively, use this.messages.slice(-2) for the last two - depends on how they are sorted. 250 | cachedListener.offChildAdded(this.messagesRef, this.messages.slice(0,2)); 251 | } 252 | ``` 253 | 254 | The first callback , `fromCacheCallback`, is passed the cached data, and loads the ListView datasource with this data. 255 | 256 | When fresh data starts arriving the second callback, `newDataArrivingCallback`, is called. In this case nothing needs to be done, however there are cases where cached data needs to be cleared. 257 | 258 | After this is called, the third callback, `snapCallback`, is called with the new snapshot. 259 | 260 | In the `_stopCachedListener` call, the first 2 messages are slices off the message array and passed to the `offChildAdded` method, the next time the screen is opened `fromCacheCallback` will be called and passed this item. 261 | 262 | The other `child_...` eventypes are all wrapped in `onChild...` methods that do nothing other than pass data through to the native method. 263 | 264 | ## Differences and Limitations 265 | 266 | There are some subtle differences between this implementation and the Firebase one that should be noted: 267 | 268 | * The Firebase `database.Reference.on(...)` method returns the provided callback function unmodified. In this module a Promise is returned that is resolved after cached data has been loaded, the callback has been called, and the native listener has been started. 269 | * If passing a context, either do so as the 5th parameter (if no cancelCallback is defined), or as the 6th parameter (if a cancelCallback is defined). I.e. don't pass a null or undefined cancelCallback, either omit it completely or put in something valid. 270 | * You should have been calling the `dbRef.off()` method previously, continue to do so but call `cachedListener.offValue(dbRef)` or `cachedListener.offChildAdded(...)`. This is when the data is actually saved to the cache. 271 | 272 | ## API 273 | 274 | See the auto-generated and hopefully up-to-date docs at: [./docs/index.md](https://github.com/cuttingsoup/react-native-firebase-local-cache/blob/master/docs/index.md) 275 | 276 | The code above should give a pretty good idea of how to use it. 277 | 278 | Or look at the future Example app which doesn't yet exist. 279 | 280 | ## Other Info 281 | 282 | ### Contributions/Criticism 283 | 284 | Let me know if there are any issues/bugs/improvements and I'll have a crack at them. Otherwise, feel free to make contributions. 285 | 286 | ### Acknowledgments 287 | 288 | I stole the basic structure of this module from [@jasonmerino](https://github.com/jasonmerino) who wrote the following module: 289 | https://github.com/jasonmerino/react-native-simple-store 290 | 291 | -------------------------------------------------------------------------------- /__tests__/index-test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const INDEX_PATH = '../src/index'; 4 | 5 | jest.unmock(INDEX_PATH); 6 | 7 | jest.mock('react-native', () => { 8 | //Local store each time the mockule is loaded. 9 | var fakeStore = {}; 10 | 11 | return ({ 12 | AsyncStorage: { 13 | setItem: jest.fn((key, value) => { 14 | return new Promise((resolve, reject) => { 15 | fakeStore[key] = value; 16 | resolve(null); 17 | }); 18 | }), 19 | getItem: jest.fn((key) => { 20 | return new Promise((resolve, reject) => { 21 | if (key in fakeStore) { 22 | resolve(fakeStore[key]); 23 | } 24 | resolve(null); 25 | }); 26 | }), 27 | removeItem: jest.fn((key) => { 28 | return new Promise((resolve, reject) => { 29 | delete fakeStore[key]; 30 | resolve(null); 31 | }); 32 | }), 33 | getAllKeys: jest.fn(() => { 34 | var keys = []; 35 | 36 | for(var key in fakeStore) { 37 | if(fakeStore.hasOwnProperty(key)) { 38 | keys.push(key); 39 | } 40 | } 41 | 42 | return new Promise((resolve) => { 43 | resolve(keys); 44 | }); 45 | }), 46 | getStore: jest.fn(() => { 47 | return fakeStore; 48 | }), 49 | } 50 | }); 51 | }); 52 | 53 | const mockUrl = "https://fake.firbase.com/"; 54 | const mockDbRefPath = "my/db/ref"; 55 | const mockDbRefUrl = mockUrl + mockDbRefPath; 56 | 57 | const makeMockDbRef = () => { 58 | return { 59 | root: mockUrl, 60 | toString: function() { return mockDbRefUrl; }, 61 | 62 | on: function(eventType, callback, cancelCallbackOrContext, context) { 63 | if(context) { 64 | callback.bind(context)("fake-data"); 65 | } else if (cancelCallbackOrContext && typeof(cancelCallbackOrContext) !== 'function') { 66 | callback.bind(cancelCallbackOrContext)("fake-data"); 67 | } else { 68 | callback("fake-data"); 69 | } 70 | }, 71 | 72 | off: jest.fn(), 73 | 74 | once: jest.fn((eventType, callback, cancelCallbackOrContext, context) => { 75 | if(context) { 76 | callback.bind(context)("fake-data"); 77 | } else if (cancelCallbackOrContext && typeof(cancelCallbackOrContext) !== 'function') { 78 | callback.bind(cancelCallbackOrContext)("fake-data"); 79 | } else { 80 | callback("fake-data"); 81 | } 82 | }), 83 | } 84 | } 85 | 86 | const makeMultiDataDbRef = () => { 87 | return { 88 | root: mockUrl, 89 | toString: function() { return mockDbRefUrl; }, 90 | 91 | on: function(eventType, callback, cancelCallbackOrContext, context) { 92 | if(context) { 93 | callback.bind(context)("fake-data1"); 94 | callback.bind(context)("fake-data2"); 95 | } else if (cancelCallbackOrContext && typeof(cancelCallbackOrContext) !== 'function') { 96 | callback.bind(cancelCallbackOrContext)("fake-data1"); 97 | callback.bind(cancelCallbackOrContext)("fake-data2"); 98 | } else { 99 | callback("fake-data1"); 100 | callback("fake-data2"); 101 | } 102 | }, 103 | 104 | off: jest.fn(), 105 | } 106 | } 107 | 108 | var mockForbiddenDbRef = { 109 | root: mockUrl, 110 | toString: function() { return mockDbRefUrl; }, 111 | 112 | on: function(eventType, callback, cancelCallbackOrContext, context) { 113 | if(context) { 114 | cancelCallbackOrContext.bind(context)("error"); 115 | } else { 116 | cancelCallbackOrContext("error"); 117 | } 118 | } 119 | } 120 | 121 | 122 | describe('onValue', () => { 123 | 124 | it('should call snapCallback followed by processedCallback', () => { 125 | const { AsyncStorage } = require('react-native'); 126 | const cachedDb = require(INDEX_PATH); 127 | 128 | var mockDbRef = makeMockDbRef(); 129 | 130 | const snapCallback = jest.fn(); 131 | snapCallback.mockReturnValueOnce("processed"); 132 | 133 | const processedCallback = jest.fn(); 134 | 135 | return cachedDb.onValue(mockDbRef, snapCallback, processedCallback).then(() => { 136 | expect(snapCallback).toBeCalledWith("fake-data"); 137 | expect(processedCallback).toBeCalledWith("processed"); 138 | }); 139 | }); 140 | 141 | it('should call the cancelled callback if permission is denied', () => { 142 | const { AsyncStorage } = require('react-native'); 143 | const cachedDb = require(INDEX_PATH); 144 | 145 | const snapCallback = jest.fn(); 146 | const processedCallback = jest.fn(); 147 | const cancelledCallback = jest.fn(); 148 | 149 | return cachedDb.onValue(mockForbiddenDbRef, snapCallback, processedCallback, cancelledCallback).then(() => { 150 | expect(snapCallback.mock.calls.length).toBe(0); 151 | expect(processedCallback.mock.calls.length).toBe(0); 152 | expect(cancelledCallback.mock.calls.length).toBe(1); 153 | expect(cancelledCallback).toBeCalledWith("error"); 154 | }); 155 | }); 156 | 157 | it('should pass context if no cancelled callback is provided', () => { 158 | const { AsyncStorage } = require('react-native'); 159 | const cachedDb = require(INDEX_PATH); 160 | 161 | const context = {str: 'test'}; 162 | 163 | var mockDbRef = makeMockDbRef(); 164 | 165 | const snapCallback = jest.fn(); 166 | snapCallback.mockReturnValueOnce('processed'); 167 | 168 | const snapCallbackWrapper = function(snap) { 169 | expect(this).toBeDefined(); 170 | expect(this.str).toBe('test'); 171 | return snapCallback(snap); 172 | } 173 | 174 | const processedCallback = jest.fn(); 175 | const processedCallbackWrapper = function(data) { 176 | expect(this).toBeDefined(); 177 | expect(this.str).toBe('test'); 178 | processedCallback(data); 179 | } 180 | 181 | return cachedDb.onValue(mockDbRef, snapCallbackWrapper, processedCallbackWrapper, context).then(() => { 182 | expect(snapCallback.mock.calls.length).toBe(1); 183 | expect(snapCallback).toBeCalledWith("fake-data"); 184 | expect(processedCallback.mock.calls.length).toBe(1); 185 | expect(processedCallback).toBeCalledWith("processed"); 186 | }); 187 | }); 188 | 189 | 190 | it('should pass context to snapCallback and processedCallback if a cancelled callback is provided but not called', () => { 191 | const { AsyncStorage } = require('react-native'); 192 | const cachedDb = require(INDEX_PATH); 193 | 194 | const context = {str: 'test'}; 195 | 196 | var mockDbRef = makeMockDbRef(); 197 | 198 | const snapCallback = jest.fn(); 199 | snapCallback.mockReturnValueOnce('processed'); 200 | 201 | const snapCallbackWrapper = function(snap) { 202 | expect(this).toBeDefined(); 203 | expect(this.str).toBe('test'); 204 | return snapCallback(snap); 205 | } 206 | 207 | const processedCallback = jest.fn(); 208 | const processedCallbackWrapper = function(data) { 209 | expect(this).toBeDefined(); 210 | expect(this.str).toBe('test'); 211 | processedCallback(data); 212 | } 213 | 214 | const cancelledCallback = jest.fn(); 215 | 216 | return cachedDb.onValue(mockDbRef, snapCallbackWrapper, processedCallbackWrapper, context).then(() => { 217 | expect(snapCallback.mock.calls.length).toBe(1); 218 | expect(snapCallback).toBeCalledWith("fake-data"); 219 | expect(processedCallback.mock.calls.length).toBe(1); 220 | expect(processedCallback).toBeCalledWith("processed"); 221 | }); 222 | }); 223 | 224 | it('should pass context to cancelledCallback if a cancelled callback is provided and called', () => { 225 | const { AsyncStorage } = require('react-native'); 226 | const cachedDb = require(INDEX_PATH); 227 | 228 | const context = {str: 'test'}; 229 | 230 | var mockDbRef = makeMockDbRef(); 231 | 232 | const snapCallback = jest.fn(); 233 | const processedCallback = jest.fn(); 234 | 235 | const cancelledCallback = jest.fn(); 236 | const cancelledCallbackWrapper = function(err) { 237 | expect(this).toBeDefined(); 238 | expect(this.str).toBe('test'); 239 | return cancelledCallback(err); 240 | } 241 | 242 | return cachedDb.onValue(mockForbiddenDbRef, snapCallback, processedCallback, cancelledCallbackWrapper, context).then(() => { 243 | expect(snapCallback.mock.calls.length).toBe(0); 244 | expect(processedCallback.mock.calls.length).toBe(0); 245 | expect(cancelledCallback.mock.calls.length).toBe(1); 246 | expect(cancelledCallback).toBeCalledWith("error"); 247 | }); 248 | }); 249 | 250 | it('should call processedCallback if there is data in the cache, but not snapCallback', () => { 251 | const { AsyncStorage } = require('react-native'); 252 | const cachedDb = require(INDEX_PATH); 253 | 254 | var mockDbRef = makeMockDbRef(); 255 | 256 | const snapCallback = jest.fn(); 257 | snapCallback.mockReturnValueOnce("processed"); 258 | snapCallback.mockReturnValueOnce("processed2"); 259 | 260 | const processedCallback = jest.fn(); 261 | 262 | return cachedDb.onValue(mockDbRef, snapCallback, processedCallback) 263 | .then(() => { return cachedDb.offValue(mockDbRef) }) 264 | .then(() => { return cachedDb.onValue(mockDbRef, snapCallback, processedCallback); }) 265 | .then(() => { 266 | expect(snapCallback.mock.calls.length).toBe(2); 267 | expect(snapCallback).toBeCalledWith("fake-data"); 268 | 269 | expect(processedCallback.mock.calls.length).toBe(3); 270 | expect(processedCallback.mock.calls[0][0]).toBe("processed"); //Original call 271 | expect(processedCallback.mock.calls[1][0]).toBe("processed"); //Cached data 272 | expect(processedCallback.mock.calls[2][0]).toBe("processed2"); // second call. 273 | 274 | expect(mockDbRef.off.mock.calls.length).toBe(1); 275 | }); 276 | 277 | }); 278 | 279 | it('should call processedCallback with correct context if there is data in the cache, but not snapCallback (context as 5th param)', () => { 280 | const { AsyncStorage } = require('react-native'); 281 | const cachedDb = require(INDEX_PATH); 282 | 283 | const context = {str: 'test'}; 284 | 285 | var mockDbRef = makeMockDbRef(); 286 | 287 | const snapCallback = jest.fn(); 288 | snapCallback.mockReturnValueOnce("processed"); 289 | snapCallback.mockReturnValueOnce("processed2"); 290 | 291 | const processedCallback = jest.fn(); 292 | const processedCallbackWrapper = function(param) { 293 | expect(this).toBeDefined(); 294 | expect(this.str).toBe('test'); 295 | return processedCallback(param); 296 | } 297 | 298 | return cachedDb.onValue(mockDbRef, snapCallback, processedCallback) 299 | .then(() => { return cachedDb.offValue(mockDbRef) }) 300 | .then(() => { return cachedDb.onValue(mockDbRef, snapCallback, processedCallbackWrapper, context); }) 301 | .then(() => { 302 | expect(snapCallback.mock.calls.length).toBe(2); 303 | expect(snapCallback).toBeCalledWith("fake-data"); 304 | 305 | expect(processedCallback.mock.calls.length).toBe(3); 306 | expect(processedCallback.mock.calls[0][0]).toBe("processed"); //Original call 307 | expect(processedCallback.mock.calls[1][0]).toBe("processed"); //Cached data 308 | expect(processedCallback.mock.calls[2][0]).toBe("processed2"); // second call. 309 | 310 | expect(mockDbRef.off.mock.calls.length).toBe(1); 311 | }); 312 | }); 313 | 314 | it('should call processedCallback with correct context if there is data in the cache, but not snapCallback (context as 6th param)', () => { 315 | const { AsyncStorage } = require('react-native'); 316 | const cachedDb = require(INDEX_PATH); 317 | 318 | const context = {str: 'test'}; 319 | 320 | var mockDbRef = makeMockDbRef(); 321 | 322 | const snapCallback = jest.fn(); 323 | snapCallback.mockReturnValueOnce("processed"); 324 | snapCallback.mockReturnValueOnce("processed2"); 325 | 326 | const processedCallback = jest.fn(); 327 | const processedCallbackWrapper = function(param) { 328 | expect(this).toBeDefined(); 329 | expect(this.str).toBe('test'); 330 | return processedCallback(param); 331 | } 332 | 333 | return cachedDb.onValue(mockDbRef, snapCallback, processedCallback) 334 | .then(() => { return cachedDb.offValue(mockDbRef) }) 335 | .then(() => { return cachedDb.onValue(mockDbRef, snapCallback, processedCallbackWrapper, ()=>{}, context); }) 336 | .then(() => { 337 | expect(snapCallback.mock.calls.length).toBe(2); 338 | expect(snapCallback).toBeCalledWith("fake-data"); 339 | 340 | expect(processedCallback.mock.calls.length).toBe(3); 341 | expect(processedCallback.mock.calls[0][0]).toBe("processed"); //Original call 342 | expect(processedCallback.mock.calls[1][0]).toBe("processed"); //Cached data 343 | expect(processedCallback.mock.calls[2][0]).toBe("processed2"); // second call. 344 | 345 | expect(mockDbRef.off.mock.calls.length).toBe(1); 346 | }); 347 | }); 348 | 349 | }); 350 | 351 | describe('onChildAdded', () => { 352 | 353 | it('should call dataAvailableCallback followed by snapCallback, but not cachedCallback if no cached data is available', () => { 354 | const { AsyncStorage } = require('react-native'); 355 | const cachedDb = require(INDEX_PATH); 356 | 357 | var mockDbRef = makeMockDbRef(); 358 | 359 | const cachedCallback = jest.fn(); 360 | 361 | const dataAvailableCallback = jest.fn(); 362 | 363 | const snapCallback = jest.fn(); 364 | 365 | return cachedDb.onChildAdded(mockDbRef, cachedCallback, dataAvailableCallback, snapCallback).then(() => { 366 | expect(cachedCallback.mock.calls.length).toBe(0); 367 | expect(dataAvailableCallback.mock.calls.length).toBe(1); 368 | expect(snapCallback.mock.calls.length).toBe(1); 369 | }); 370 | }); 371 | 372 | it('should call all callbacks if cached data is available', () => { 373 | const { AsyncStorage } = require('react-native'); 374 | const cachedDb = require(INDEX_PATH); 375 | 376 | var mockDbRef = makeMockDbRef(); 377 | 378 | //Add something to the cache. 379 | AsyncStorage.setItem(`@FirebaseLocalCache:child_added:${mockDbRefPath}`, JSON.stringify('cached data')); 380 | 381 | const cachedCallback = jest.fn(); 382 | 383 | const dataAvailableCallback = jest.fn(); 384 | 385 | const snapCallback = jest.fn(); 386 | 387 | return cachedDb.onChildAdded(mockDbRef, cachedCallback, dataAvailableCallback, snapCallback).then(() => { 388 | expect(cachedCallback.mock.calls.length).toBe(1); 389 | expect(cachedCallback).toBeCalledWith('cached data'); 390 | 391 | expect(dataAvailableCallback.mock.calls.length).toBe(1); 392 | expect(snapCallback.mock.calls.length).toBe(1); 393 | }); 394 | }); 395 | 396 | it('should call only call dataAvailableCallback once', () => { 397 | const { AsyncStorage } = require('react-native'); 398 | const cachedDb = require(INDEX_PATH); 399 | 400 | //Make sure multiple sets of data arrive. 401 | var mockDbRef = makeMultiDataDbRef(); 402 | 403 | //Add something to the cache. 404 | AsyncStorage.setItem(`@FirebaseLocalCache:child_added:${mockDbRefPath}`, JSON.stringify('cached data')); 405 | 406 | const cachedCallback = jest.fn(); 407 | 408 | const dataAvailableCallback = jest.fn(); 409 | 410 | const snapCallback = jest.fn(); 411 | 412 | return cachedDb.onChildAdded(mockDbRef, cachedCallback, dataAvailableCallback, snapCallback).then(() => { 413 | expect(cachedCallback.mock.calls.length).toBe(1); 414 | expect(cachedCallback).toBeCalledWith('cached data'); 415 | 416 | expect(dataAvailableCallback.mock.calls.length).toBe(1); 417 | expect(snapCallback.mock.calls.length).toBe(2); 418 | expect(snapCallback.mock.calls[0][0]).toBe("fake-data1"); 419 | expect(snapCallback.mock.calls[1][0]).toBe("fake-data2"); 420 | }); 421 | }); 422 | 423 | it('should pass context correctly with no errorCallback', () => { 424 | const { AsyncStorage } = require('react-native'); 425 | const cachedDb = require(INDEX_PATH); 426 | 427 | const context = {str: 'test'}; 428 | 429 | //Make sure multiple sets of data arrive. 430 | var mockDbRef = makeMockDbRef(); 431 | 432 | //Add something to the cache. 433 | AsyncStorage.setItem(`@FirebaseLocalCache:child_added:${mockDbRefPath}`, JSON.stringify('cached data')); 434 | 435 | const cachedCallback = jest.fn(); 436 | const cachedCallbackWrapper = function() { 437 | expect(this).toBeDefined(); 438 | expect(this.str).toBe('test'); 439 | return cachedCallback(); 440 | } 441 | 442 | const dataAvailableCallback = jest.fn(); 443 | const dataAvailableCallbackWrapper = function() { 444 | expect(this).toBeDefined(); 445 | expect(this.str).toBe('test'); 446 | return dataAvailableCallback(); 447 | } 448 | 449 | const snapCallback = jest.fn(); 450 | const snapCallbackWrapper = function() { 451 | expect(this).toBeDefined(); 452 | expect(this.str).toBe('test'); 453 | return snapCallback(); 454 | } 455 | 456 | return cachedDb.onChildAdded(mockDbRef, cachedCallbackWrapper, dataAvailableCallbackWrapper, snapCallbackWrapper, context).then(() => { 457 | expect(cachedCallback.mock.calls.length).toBe(1); 458 | expect(dataAvailableCallback.mock.calls.length).toBe(1); 459 | expect(snapCallback.mock.calls.length).toBe(1); 460 | }); 461 | }); 462 | 463 | it('should pass context correctly with errorCallback', () => { 464 | const { AsyncStorage } = require('react-native'); 465 | const cachedDb = require(INDEX_PATH); 466 | 467 | const context = {str: 'test'}; 468 | 469 | //Make sure multiple sets of data arrive. 470 | var mockDbRef = makeMockDbRef(); 471 | 472 | //Add something to the cache. 473 | AsyncStorage.setItem(`@FirebaseLocalCache:child_added:${mockDbRefPath}`, JSON.stringify('cached data')); 474 | 475 | const cachedCallback = jest.fn(); 476 | const cachedCallbackWrapper = function() { 477 | expect(this).toBeDefined(); 478 | expect(this.str).toBe('test'); 479 | return cachedCallback(); 480 | } 481 | 482 | const dataAvailableCallback = jest.fn(); 483 | const dataAvailableCallbackWrapper = function() { 484 | expect(this).toBeDefined(); 485 | expect(this.str).toBe('test'); 486 | return dataAvailableCallback(); 487 | } 488 | 489 | const snapCallback = jest.fn(); 490 | const snapCallbackWrapper = function() { 491 | expect(this).toBeDefined(); 492 | expect(this.str).toBe('test'); 493 | return snapCallback(); 494 | } 495 | 496 | const errorCallback = jest.fn(); 497 | 498 | return cachedDb.onChildAdded(mockDbRef, cachedCallbackWrapper, dataAvailableCallbackWrapper, snapCallbackWrapper, errorCallback, context).then(() => { 499 | expect(errorCallback.mock.calls.length).toBe(0); 500 | expect(cachedCallback.mock.calls.length).toBe(1); 501 | expect(dataAvailableCallback.mock.calls.length).toBe(1); 502 | expect(snapCallback.mock.calls.length).toBe(1); 503 | }); 504 | }); 505 | 506 | it('should call errorCallback if error occurs and pass context', () => { 507 | const { AsyncStorage } = require('react-native'); 508 | const cachedDb = require(INDEX_PATH); 509 | 510 | const context = {str: 'test'}; 511 | 512 | //Use forbidden db ref. 513 | var mockDbRef = mockForbiddenDbRef; 514 | 515 | const cachedCallback = jest.fn(); 516 | const dataAvailableCallback = jest.fn(); 517 | const snapCallback = jest.fn(); 518 | const errorCallback = jest.fn(); 519 | const errorCallbackWrapper = function() { 520 | expect(this).toBeDefined(); 521 | expect(this.str).toBe('test'); 522 | return errorCallback(); 523 | } 524 | 525 | return cachedDb.onChildAdded(mockDbRef, cachedCallback, dataAvailableCallback, snapCallback, errorCallbackWrapper, context).then(() => { 526 | expect(errorCallback.mock.calls.length).toBe(1); 527 | expect(cachedCallback.mock.calls.length).toBe(0); 528 | expect(dataAvailableCallback.mock.calls.length).toBe(0); 529 | expect(snapCallback.mock.calls.length).toBe(0); 530 | }); 531 | }); 532 | }); 533 | 534 | describe('offChildAdded', () => { 535 | 536 | it('should write data to the async store', () => { 537 | const { AsyncStorage } = require('react-native'); 538 | const cachedDb = require(INDEX_PATH); 539 | 540 | var mockDbRef = makeMockDbRef(); 541 | 542 | //Expected path to store at. 543 | const storageKey = `@FirebaseLocalCache:child_added:${mockDbRefPath}` 544 | 545 | return cachedDb.offChildAdded(mockDbRef, 'amIStored') 546 | .then(() => AsyncStorage.getItem(storageKey)) 547 | .then((result) => { 548 | expect(result).toBe(JSON.stringify('amIStored')); 549 | }); 550 | }); 551 | }); 552 | 553 | describe('twice', () => { 554 | 555 | it('should call snapCallback followed by processedCallback, with no cached data', (done) => { 556 | const { AsyncStorage } = require('react-native'); 557 | const cachedDb = require(INDEX_PATH); 558 | 559 | var mockDbRef = makeMockDbRef(); 560 | 561 | const snapCallback = jest.fn(); 562 | snapCallback.mockReturnValueOnce("processed"); 563 | 564 | const processedCallback = function(data) { 565 | expect(snapCallback).toBeCalled(); 566 | expect(data).toBe('processed'); 567 | done(); 568 | }; 569 | 570 | cachedDb.twice(mockDbRef, snapCallback, processedCallback); 571 | }); 572 | 573 | it('should call processedCallback with cached data, then snapCallback followed by processedCallback', (done) => { 574 | const { AsyncStorage } = require('react-native'); 575 | const cachedDb = require(INDEX_PATH); 576 | 577 | const context = {str: 'test'}; 578 | 579 | var mockDbRef = makeMockDbRef(); 580 | 581 | var count = 0; 582 | 583 | AsyncStorage.setItem(`@FirebaseLocalCache:twice:${mockDbRefPath}`, JSON.stringify('cached')); 584 | 585 | const snapCallback = jest.fn(function() { 586 | //Check context. 587 | expect(this).toBeDefined(); 588 | expect(this.str).toBe('test'); 589 | return 'processed'; 590 | }); 591 | 592 | const processedCallback = function(data) { 593 | //Check context. 594 | expect(this).toBeDefined(); 595 | expect(this.str).toBe('test'); 596 | 597 | if(count == 0) { 598 | expect(data).toBe('cached'); 599 | count++; 600 | } else { 601 | expect(snapCallback.mock.calls.length).toBe(1); 602 | expect(data).toBe('processed'); 603 | 604 | AsyncStorage.getItem(`@FirebaseLocalCache:twice:${mockDbRefPath}`).then((item) => { 605 | expect(JSON.parse(item)).toBe('processed'); 606 | done(); 607 | }) 608 | } 609 | }; 610 | 611 | cachedDb.twice(mockDbRef, snapCallback, processedCallback, context); 612 | }); 613 | 614 | }); 615 | 616 | describe('clearCacheForRef', () => { 617 | 618 | it('should delete items in the AsyncStorage for a particular db ref', () => { 619 | const { AsyncStorage } = require('react-native'); 620 | const cachedDb = require(INDEX_PATH); 621 | 622 | var mockDbRef = makeMockDbRef(); 623 | 624 | const snapCallback = jest.fn(); 625 | snapCallback.mockReturnValueOnce("processed"); 626 | 627 | const processedCallback = jest.fn(); 628 | 629 | return cachedDb.onValue(mockDbRef, snapCallback, processedCallback) 630 | .then(() => { return cachedDb.offValue(mockDbRef) }) //put something in the cache. 631 | .then(() => { 632 | var count = 0; 633 | 634 | for(var propName in AsyncStorage.getStore()) { 635 | if(AsyncStorage.getStore().hasOwnProperty(propName)) { 636 | count++; 637 | } 638 | } 639 | 640 | expect(count).toBe(1); 641 | }).then(() => { 642 | return cachedDb.clearCacheForRef(mockDbRef); 643 | }).then(() => { 644 | for(var propName in AsyncStorage.getStore()) { 645 | if(AsyncStorage.getStore().hasOwnProperty(propName)) { 646 | console.log(propName + ': ' + AsyncStorage.getStore()[propName]); 647 | expect('unreachable code').toBe('not reached...'); 648 | } 649 | } 650 | }); 651 | }); 652 | 653 | }); 654 | 655 | describe('clearCache', () => { 656 | 657 | it('should delete all items in the AsyncStorage', () => { 658 | const { AsyncStorage } = require('react-native'); 659 | const cachedDb = require(INDEX_PATH); 660 | 661 | var mockDbRef = makeMockDbRef(); 662 | 663 | const snapCallback = jest.fn(); 664 | snapCallback.mockReturnValueOnce("processed"); 665 | 666 | const processedCallback = jest.fn(); 667 | 668 | return cachedDb.onValue(mockDbRef, snapCallback, processedCallback) 669 | .then(() => { return cachedDb.offValue(mockDbRef) }) //put something in the cache. 670 | .then(() => { 671 | var count = 0; 672 | 673 | for(var propName in AsyncStorage.getStore()) { 674 | if(AsyncStorage.getStore().hasOwnProperty(propName)) { 675 | count++; 676 | } 677 | } 678 | 679 | expect(count).toBe(1); 680 | }).then(() => { 681 | return cachedDb.clearCache(); 682 | }).then(() => { 683 | for(var propName in AsyncStorage.getStore()) { 684 | if(AsyncStorage.getStore().hasOwnProperty(propName)) { 685 | console.log('Uh oh! >>> ' + propName + ': ' + AsyncStorage.getStore()[propName]); 686 | expect('unreachable code').toBe('not reached...'); 687 | } 688 | } 689 | }); 690 | }); 691 | 692 | }); -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /** 3 | * @overview A simple wrapper to Firebase listeners to add local caching of data. 4 | * @license MIT 5 | */ 6 | 7 | var _reactNative = require('react-native'); 8 | 9 | var snapPeak = {}; 10 | 11 | var acceptedOnVerbs = ['value', 'child_added', 'twice']; 12 | 13 | function emptyFunction() {}; 14 | 15 | function getStorageKeyFromDbRef(dbRef, eventType) { 16 | var location = ""; 17 | 18 | if (dbRef.root) { 19 | location = dbRef.toString().substring(dbRef.root.toString().length); 20 | } else { 21 | //This is a query, not a ref. 22 | location = dbRef.toString().substring(dbRef.ref.root.toString().length); 23 | } 24 | 25 | return '@FirebaseLocalCache:' + eventType + ':' + location; 26 | } 27 | 28 | /** 29 | * Call a function with a single argument (arg), and bind the correct context. If no cancelCallback is defined, use cancelCallbackOrContext as context, otherwise use context. 30 | * @param {*} functionToCall The function that should be called - must take one argument. 31 | * @param {*} arg The argument to pass to functionToCall 32 | * @param {*} cancelCallbackOrContext A callback, or context if no callback is provided. 33 | * @param {*} context A context to bind to the funcitonToCall. 34 | */ 35 | function callWithContext(functionToCall, arg, cancelCallbackOrContext, context) { 36 | if (cancelCallbackOrContext) { 37 | if (context) { 38 | functionToCall.bind(context)(arg); 39 | } else { 40 | functionToCall.bind(cancelCallbackOrContext)(arg); 41 | } 42 | } else { 43 | functionToCall(arg); 44 | } 45 | } 46 | 47 | var cachedDb = { 48 | 49 | /** 50 | * Create an 'value' on listener that will first return a cached version of the endpoint. 51 | * @param {firebase.database.Reference} dbRef Firebase database reference to listen at. 52 | * @param {Function} snapCallback Callback called when a new snapshot is available. Should return a JSON.stringify-able object that will be cached. 53 | * @param {Function} processedCallback Callback called with data returned by snapCallback, or cached data if available. 54 | * @param {Function|Object} cancelCallbackOrContext An optional callback that will be notified if your event subscription is ever canceled because your client does not have permission to read this data (or it had permission but has now lost it). This callback will be passed an Error object indicating why the failure occurred. 55 | * @param {Object} context If provided, this object will be used as this when calling your callback(s). 56 | * @returns {Promise} Resolves when the cache has been read and listener attached to DB ref. 57 | */ 58 | onValue: function onValue(dbRef, snapCallback, processedCallback, cancelCallbackOrContext, context) { 59 | var storageKey = getStorageKeyFromDbRef(dbRef, 'value'); 60 | 61 | return _reactNative.AsyncStorage.getItem(storageKey).then(function (value) { 62 | // Called processedCallback with cached value. 63 | if (value !== null) { 64 | var cachedVal = JSON.parse(value); 65 | callWithContext(processedCallback, cachedVal, cancelCallbackOrContext, context); 66 | } 67 | }).then(function () { 68 | var callbackPeak = function callbackPeak(snap) { 69 | var processed = snapCallback.bind(this)(snap); 70 | snapPeak[storageKey] = JSON.stringify(processed); 71 | processedCallback.bind(this)(processed); 72 | }; 73 | dbRef.on('value', callbackPeak, cancelCallbackOrContext, context); 74 | }); 75 | }, 76 | 77 | 78 | /** 79 | * Remove any listeners from the specified ref, and save any existing data to the cache. 80 | * @param {firebase.database.Reference} dbRef Firebase database reference to clear. 81 | * @returns {Promise} Promis that will resolve after listener is switched off and cache has been written. 82 | */ 83 | offValue: function offValue(dbRef) { 84 | var storageKey = getStorageKeyFromDbRef(dbRef, 'value'); 85 | 86 | //Turn listener off. 87 | dbRef.off(); 88 | 89 | return new Promise(function (resolve, reject) { 90 | if (storageKey in snapPeak) { 91 | var dataToCache = snapPeak[storageKey]; 92 | delete snapPeak[storageKey]; 93 | resolve(_reactNative.AsyncStorage.setItem(storageKey, dataToCache)); 94 | } else { 95 | resolve(null); 96 | } 97 | }); 98 | }, 99 | 100 | 101 | /** 102 | * Create an 'child_added' on listener that will first return any cached data saved by a call to offChildAdded. When fresh data arrives, newDataArrivingCallback will be called once, followed by the standard snap callback. From this point on only the snapCallback will be called. 103 | * @param {firebase.database.Reference} dbRef Firebase database reference to listen at. 104 | * @param {*} fromCacheCallback Callback that will be called with cached data if any is available. 105 | * @param {*} newDataArrivingCallback Callback called immediately before fresh data starts arriving. 106 | * @param {*} snapCallback Callback called when new data snapshots arrive from the server. 107 | * @param {*} cancelCallbackOrContext Optional callback that will be called in the case of an error, e.g. forbidden. 108 | * @param {*} context Optional context that will be bound to `this` in callbacks. 109 | * @returns {Promise} Resolves when the cache has been read and listener attached to DB ref. 110 | */ 111 | onChildAdded: function onChildAdded(dbRef, fromCacheCallback, newDataArrivingCallback, snapCallback, cancelCallbackOrContext, context) { 112 | var storageKey = getStorageKeyFromDbRef(dbRef, 'child_added'); 113 | 114 | return _reactNative.AsyncStorage.getItem(storageKey).then(function (value) { 115 | // Called processedCallback with cached value. 116 | if (value !== null) { 117 | var cachedVal = JSON.parse(value); 118 | callWithContext(fromCacheCallback, cachedVal, cancelCallbackOrContext, context); 119 | } 120 | }).then(function () { 121 | var firstData = true; 122 | 123 | var callbackIntercept = function callbackIntercept(snap) { 124 | //Call the data arriving callback the first time new data comes in. 125 | if (firstData) { 126 | firstData = false; 127 | newDataArrivingCallback.bind(this)(); 128 | } 129 | //Then call the snapCallback as normal. 130 | snapCallback.bind(this)(snap); 131 | }; 132 | 133 | dbRef.on('child_added', callbackIntercept, cancelCallbackOrContext, context); 134 | }); 135 | }, 136 | 137 | 138 | /** 139 | * Turn off listeners at a certain database.Reference, and cache the data passed in so that it can be passed to a new "child_added" listener if one is created. 140 | * @param {*} dbRef Reference to stop listening at. 141 | * @param {*} dataToCache Data that should be cached for this location. Tip: [].slice(-20) to keep the latest 20 items. 142 | */ 143 | offChildAdded: function offChildAdded(dbRef, dataToCache) { 144 | var storageKey = getStorageKeyFromDbRef(dbRef, 'child_added'); 145 | 146 | //Turn listener off. 147 | dbRef.off(); 148 | 149 | return new Promise(function (resolve, reject) { 150 | resolve(_reactNative.AsyncStorage.setItem(storageKey, JSON.stringify(dataToCache))); 151 | }); 152 | }, 153 | 154 | 155 | /** 156 | * Wrapper around Firebase on child_removed listener. 157 | * @param {*} dbRef Database reference to listen at. 158 | * @param {*} callback A callback that fires when the specified event occurs. The callback will be passed a DataSnapshot. For ordering purposes, "child_added", "child_changed", and "child_moved" will also be passed a string containing the key of the previous child, by sort order, or null if it is the first child. 159 | * @param {*} cancelCallbackOrContext An optional callback that will be notified if your event subscription is ever canceled because your client does not have permission to read this data (or it had permission but has now lost it). This callback will be passed an Error object indicating why the failure occurred. 160 | * @param {*} context If provided, this object will be used as this when calling your callback(s). 161 | */ 162 | onChildRemoved: function onChildRemoved(dbRef, callback, cancelCallbackOrContext, context) { 163 | return dbRef.on('child_removed', callback, cancelCallbackOrContext, context); 164 | }, 165 | 166 | 167 | /** 168 | * Wrapper around Firebase on child_changed listener. 169 | * @param {*} dbRef Database reference to listen at. 170 | * @param {*} callback A callback that fires when the specified event occurs. The callback will be passed a DataSnapshot. For ordering purposes, "child_added", "child_changed", and "child_moved" will also be passed a string containing the key of the previous child, by sort order, or null if it is the first child. 171 | * @param {*} cancelCallbackOrContext An optional callback that will be notified if your event subscription is ever canceled because your client does not have permission to read this data (or it had permission but has now lost it). This callback will be passed an Error object indicating why the failure occurred. 172 | * @param {*} context If provided, this object will be used as this when calling your callback(s). 173 | */ 174 | onChildChanged: function onChildChanged(dbRef, callback, cancelCallbackOrContext, context) { 175 | return dbRef.on('child_changed', callback, cancelCallbackOrContext, context); 176 | }, 177 | 178 | 179 | /** 180 | * Wrapper around Firebase on child_moved listener. 181 | * @param {*} dbRef Database reference to listen at. 182 | * @param {*} callback A callback that fires when the specified event occurs. The callback will be passed a DataSnapshot. For ordering purposes, "child_added", "child_changed", and "child_moved" will also be passed a string containing the key of the previous child, by sort order, or null if it is the first child. 183 | * @param {*} cancelCallbackOrContext An optional callback that will be notified if your event subscription is ever canceled because your client does not have permission to read this data (or it had permission but has now lost it). This callback will be passed an Error object indicating why the failure occurred. 184 | * @param {*} context If provided, this object will be used as this when calling your callback(s). 185 | */ 186 | onChildMoved: function onChildMoved(dbRef, callback, cancelCallbackOrContext, context) { 187 | return dbRef.on('child_moved', callback, cancelCallbackOrContext, context); 188 | }, 189 | 190 | 191 | /** 192 | * Twice, one better than once! Operates in a similar way to `onValue`, however `snapCallback` will only ever be called once when fresh data arrives. The value returned by `snapCallback` will be cached immediately, then passed to the `processedCallback`. If cached data is available when the listener is first turned on, it will be loaded and passed to `processedCallback`. Once data is cached then, each call to `twice` will call `processedCallback` twice, once with cached data, then once with fresh data after being processed by `snapCallback`. 193 | * @param {*} dbRef Database reference to listen at. 194 | * @param {Function} snapCallback Callback called when a new snapshot is available. Should return a JSON.stringify-able object that will be cached. 195 | * @param {Function} processedCallback Callback called maximum of twice - once with cached data, once with freshly processed data. 196 | * @param {Function|Object} cancelCallbackOrContext An optional callback that will be notified if your event subscription is ever canceled because your client does not have permission to read this data (or it had permission but has now lost it). This callback will be passed an Error object indicating why the failure occurred. 197 | * @param {Object} context If provided, this object will be used as this when calling your callback(s). 198 | * @returns {Promise} Resolves when the cache has been read and listener attached to DB ref. 199 | */ 200 | twice: function twice(dbRef, snapCallback, processedCallback, cancelCallbackOrContext, context) { 201 | var storageKey = getStorageKeyFromDbRef(dbRef, 'twice'); 202 | 203 | return _reactNative.AsyncStorage.getItem(storageKey).then(function (value) { 204 | // Called processedCallback with cached value. 205 | if (value !== null) { 206 | var cachedVal = JSON.parse(value); 207 | callWithContext(processedCallback, cachedVal, cancelCallbackOrContext, context); 208 | } 209 | }).then(function () { 210 | var callbackPeak = function callbackPeak(snap) { 211 | var processed = snapCallback.bind(this)(snap); 212 | //Store to cache. 213 | _reactNative.AsyncStorage.setItem(storageKey, JSON.stringify(processed)).then(function () { 214 | processedCallback.bind(this)(processed); 215 | }.bind(this)); 216 | }; 217 | dbRef.once('value', callbackPeak, cancelCallbackOrContext, context); 218 | }); 219 | }, 220 | 221 | 222 | /** 223 | * Remove the currently cached data for a particular database.Reference. If there are any listeners still active, they will re-write their data to the cache when the .off method is called. 224 | * @param {firebase.database.Reference} dbRef Firebase database reference to clear. 225 | * @returns {Promise} Promise that resolves once all cached data for this ref has been cleared. 226 | */ 227 | clearCacheForRef: function clearCacheForRef(dbRef) { 228 | var location = dbRef.toString().substring(dbRef.root.toString().length); 229 | 230 | var promises = []; 231 | 232 | acceptedOnVerbs.forEach(function (eventType) { 233 | var storageKey = '@FirebaseLocalCache:' + eventType + ':' + location; 234 | promises.push(_reactNative.AsyncStorage.removeItem(storageKey)); 235 | }); 236 | 237 | return Promise.all(promises); 238 | }, 239 | 240 | 241 | /** 242 | * Remove all currently cached data. If there are any listeners still active, they will re-write their data to the cache when the .off method is called. 243 | * @returns {Promise} Promise that resolves when all cached data has been deleted. 244 | */ 245 | clearCache: function clearCache() { 246 | return _reactNative.AsyncStorage.getAllKeys().then(function (keys) { 247 | var promises = []; 248 | 249 | keys.forEach(function (key) { 250 | if (key.startsWith('@FirebaseLocalCache:')) { 251 | //delete it from the cache if it exists. 252 | promises.push(_reactNative.AsyncStorage.removeItem(key)); 253 | } 254 | }); 255 | 256 | return Promise.all(promises); 257 | }); 258 | } 259 | }; 260 | 261 | module.exports = cachedDb; -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # Global 2 | 3 | 4 | 5 | 6 | 7 | * * * 8 | 9 | ### callWithContext(functionToCall, arg, cancelCallbackOrContext, context) 10 | 11 | Call a function with a single argument (arg), and bind the correct context. If no cancelCallback is defined, use cancelCallbackOrContext as context, otherwise use context. 12 | 13 | **Parameters** 14 | 15 | **functionToCall**: `*`, The function that should be called - must take one argument. 16 | 17 | **arg**: `*`, The argument to pass to functionToCall 18 | 19 | **cancelCallbackOrContext**: `*`, A callback, or context if no callback is provided. 20 | 21 | **context**: `*`, A context to bind to the funcitonToCall. 22 | 23 | 24 | 25 | ### onValue(dbRef, snapCallback, processedCallback, cancelCallbackOrContext, context) 26 | 27 | Create an 'value' on listener that will first return a cached version of the endpoint. 28 | 29 | **Parameters** 30 | 31 | **dbRef**: `firebase.database.Reference`, Firebase database reference to listen at. 32 | 33 | **snapCallback**: `function`, Callback called when a new snapshot is available. Should return a JSON.stringify-able object that will be cached. 34 | 35 | **processedCallback**: `function`, Callback called with data returned by snapCallback, or cached data if available. 36 | 37 | **cancelCallbackOrContext**: `function | Object`, An optional callback that will be notified if your event subscription is ever canceled because your client does not have permission to read this data (or it had permission but has now lost it). This callback will be passed an Error object indicating why the failure occurred. 38 | 39 | **context**: `Object`, If provided, this object will be used as this when calling your callback(s). 40 | 41 | **Returns**: `Promise`, Resolves when the cache has been read and listener attached to DB ref. 42 | 43 | 44 | ### offValue(dbRef) 45 | 46 | Remove any listeners from the specified ref, and save any existing data to the cache. 47 | 48 | **Parameters** 49 | 50 | **dbRef**: `firebase.database.Reference`, Firebase database reference to clear. 51 | 52 | **Returns**: `Promise`, Promis that will resolve after listener is switched off and cache has been written. 53 | 54 | 55 | ### onChildAdded(dbRef, fromCacheCallback, newDataArrivingCallback, snapCallback, cancelCallbackOrContext, context) 56 | 57 | Create an 'child_added' on listener that will first return any cached data saved by a call to offChildAdded. When fresh data arrives, newDataArrivingCallback will be called once, followed by the standard snap callback. From this point on only the snapCallback will be called. 58 | 59 | **Parameters** 60 | 61 | **dbRef**: `firebase.database.Reference`, Firebase database reference to listen at. 62 | 63 | **fromCacheCallback**: `*`, Callback that will be called with cached data if any is available. 64 | 65 | **newDataArrivingCallback**: `*`, Callback called immediately before fresh data starts arriving. 66 | 67 | **snapCallback**: `*`, Callback called when new data snapshots arrive from the server. 68 | 69 | **cancelCallbackOrContext**: `*`, Optional callback that will be called in the case of an error, e.g. forbidden. 70 | 71 | **context**: `*`, Optional context that will be bound to `this` in callbacks. 72 | 73 | **Returns**: `Promise`, Resolves when the cache has been read and listener attached to DB ref. 74 | 75 | 76 | ### offChildAdded(dbRef, dataToCache) 77 | 78 | Turn off listeners at a certain database.Reference, and cache the data passed in so that it can be passed to a new "child_added" listener if one is created. 79 | 80 | **Parameters** 81 | 82 | **dbRef**: `*`, Reference to stop listening at. 83 | 84 | **dataToCache**: `*`, Data that should be cached for this location. Tip: [].slice(-20) to keep the latest 20 items. 85 | 86 | 87 | 88 | ### onChildRemoved(dbRef, callback, cancelCallbackOrContext, context) 89 | 90 | Wrapper around Firebase on child_removed listener. 91 | 92 | **Parameters** 93 | 94 | **dbRef**: `*`, Database reference to listen at. 95 | 96 | **callback**: `*`, A callback that fires when the specified event occurs. The callback will be passed a DataSnapshot. For ordering purposes, "child_added", "child_changed", and "child_moved" will also be passed a string containing the key of the previous child, by sort order, or null if it is the first child. 97 | 98 | **cancelCallbackOrContext**: `*`, An optional callback that will be notified if your event subscription is ever canceled because your client does not have permission to read this data (or it had permission but has now lost it). This callback will be passed an Error object indicating why the failure occurred. 99 | 100 | **context**: `*`, If provided, this object will be used as this when calling your callback(s). 101 | 102 | 103 | 104 | ### onChildChanged(dbRef, callback, cancelCallbackOrContext, context) 105 | 106 | Wrapper around Firebase on child_changed listener. 107 | 108 | **Parameters** 109 | 110 | **dbRef**: `*`, Database reference to listen at. 111 | 112 | **callback**: `*`, A callback that fires when the specified event occurs. The callback will be passed a DataSnapshot. For ordering purposes, "child_added", "child_changed", and "child_moved" will also be passed a string containing the key of the previous child, by sort order, or null if it is the first child. 113 | 114 | **cancelCallbackOrContext**: `*`, An optional callback that will be notified if your event subscription is ever canceled because your client does not have permission to read this data (or it had permission but has now lost it). This callback will be passed an Error object indicating why the failure occurred. 115 | 116 | **context**: `*`, If provided, this object will be used as this when calling your callback(s). 117 | 118 | 119 | 120 | ### onChildMoved(dbRef, callback, cancelCallbackOrContext, context) 121 | 122 | Wrapper around Firebase on child_moved listener. 123 | 124 | **Parameters** 125 | 126 | **dbRef**: `*`, Database reference to listen at. 127 | 128 | **callback**: `*`, A callback that fires when the specified event occurs. The callback will be passed a DataSnapshot. For ordering purposes, "child_added", "child_changed", and "child_moved" will also be passed a string containing the key of the previous child, by sort order, or null if it is the first child. 129 | 130 | **cancelCallbackOrContext**: `*`, An optional callback that will be notified if your event subscription is ever canceled because your client does not have permission to read this data (or it had permission but has now lost it). This callback will be passed an Error object indicating why the failure occurred. 131 | 132 | **context**: `*`, If provided, this object will be used as this when calling your callback(s). 133 | 134 | 135 | 136 | ### twice(dbRef, snapCallback, processedCallback, cancelCallbackOrContext, context) 137 | 138 | Twice, one better than once! Operates in a similar way to `onValue`, however `snapCallback` will only ever be called once when fresh data arrives. The value returned by `snapCallback` will be cached immediately, then passed to the `processedCallback`. If cached data is available when the listener is first turned on, it will be loaded and passed to `processedCallback`. Once data is cached then, each call to `twice` will call `processedCallback` twice, once with cached data, then once with fresh data after being processed by `snapCallback`. 139 | 140 | **Parameters** 141 | 142 | **dbRef**: `*`, Database reference to listen at. 143 | 144 | **snapCallback**: `function`, Callback called when a new snapshot is available. Should return a JSON.stringify-able object that will be cached. 145 | 146 | **processedCallback**: `function`, Callback called maximum of twice - once with cached data, once with freshly processed data. 147 | 148 | **cancelCallbackOrContext**: `function | Object`, An optional callback that will be notified if your event subscription is ever canceled because your client does not have permission to read this data (or it had permission but has now lost it). This callback will be passed an Error object indicating why the failure occurred. 149 | 150 | **context**: `Object`, If provided, this object will be used as this when calling your callback(s). 151 | 152 | **Returns**: `Promise`, Resolves when the cache has been read and listener attached to DB ref. 153 | 154 | 155 | ### clearCacheForRef(dbRef) 156 | 157 | Remove the currently cached data for a particular database.Reference. If there are any listeners still active, they will re-write their data to the cache when the .off method is called. 158 | 159 | **Parameters** 160 | 161 | **dbRef**: `firebase.database.Reference`, Firebase database reference to clear. 162 | 163 | **Returns**: `Promise`, Promise that resolves once all cached data for this ref has been cleared. 164 | 165 | 166 | ### clearCache() 167 | 168 | Remove all currently cached data. If there are any listeners still active, they will re-write their data to the cache when the .off method is called. 169 | 170 | **Returns**: `Promise`, Promise that resolves when all cached data has been deleted. 171 | 172 | 173 | 174 | * * * 175 | 176 | 177 | 178 | 179 | 180 | **License:** MIT 181 | 182 | **Overview:** A simple wrapper to Firebase listeners to add local caching of data. 183 | 184 | 185 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-firebase-local-cache", 3 | "version": "0.4.0", 4 | "description": "Speed up the apparent load time of screens in your app by caching content. Wraps the Firebase 'on' and 'once' methods to make caching easy!", 5 | "main": "dist/index.js", 6 | "scripts": { 7 | "dist": "babel src -d dist", 8 | "gen-docs": "./node_modules/.bin/jsdox dist/index.js --output docs", 9 | "preversion": "npm run dist -s ; npm run gen-docs -s ; git add docs/index.md dist/index.js", 10 | "test": "./node_modules/.bin/jest" 11 | }, 12 | "jest": { 13 | "scriptPreprocessor": "/node_modules/babel-jest", 14 | "unmockedModulePathPatterns": [ 15 | "/node_modules/react-native" 16 | ], 17 | "testFileExtensions": [ 18 | "js" 19 | ], 20 | "collectCoverage": true 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "https://github.com/cuttingsoup/react-native-firebase-local-cache.git" 25 | }, 26 | "keywords": [ 27 | "React Native", 28 | "iOS", 29 | "Android", 30 | "AsyncStorage", 31 | "data store", 32 | "key value store", 33 | "firebase", 34 | "cache" 35 | ], 36 | "author": "Hugh Ackland", 37 | "license": "MIT", 38 | "dependencies": {}, 39 | "devDependencies": { 40 | "babel-cli": "^6.7.7", 41 | "babel-jest": "^9.0.3", 42 | "babel-preset-es2015": "^6.6.0", 43 | "babel-preset-stage-0": "^6.5.0", 44 | "coveralls": "^2.13.0", 45 | "jest-cli": "^13.2.3", 46 | "jsdox": "^0.4.10", 47 | "lodash.merge": "^4.6.0", 48 | "react": "^0.14.7", 49 | "react-native": "^0.22.0" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /** 3 | * @overview A simple wrapper to Firebase listeners to add local caching of data. 4 | * @license MIT 5 | */ 6 | import { AsyncStorage } from 'react-native'; 7 | 8 | var snapPeak = {}; 9 | 10 | const acceptedOnVerbs = ['value', 'child_added', 'twice']; 11 | 12 | function emptyFunction(){}; 13 | 14 | function getStorageKeyFromDbRef(dbRef, eventType) { 15 | var location = ""; 16 | 17 | if(dbRef.root) { 18 | location = dbRef.toString().substring(dbRef.root.toString().length); 19 | } else { //This is a query, not a ref. 20 | location = dbRef.toString().substring(dbRef.ref.root.toString().length); 21 | } 22 | 23 | return `@FirebaseLocalCache:${eventType}:${location}`; 24 | } 25 | 26 | /** 27 | * Call a function with a single argument (arg), and bind the correct context. If no cancelCallback is defined, use cancelCallbackOrContext as context, otherwise use context. 28 | * @param {*} functionToCall The function that should be called - must take one argument. 29 | * @param {*} arg The argument to pass to functionToCall 30 | * @param {*} cancelCallbackOrContext A callback, or context if no callback is provided. 31 | * @param {*} context A context to bind to the funcitonToCall. 32 | */ 33 | function callWithContext(functionToCall, arg, cancelCallbackOrContext, context) { 34 | if(cancelCallbackOrContext) { 35 | if(context) { 36 | functionToCall.bind(context)(arg); 37 | } else { 38 | functionToCall.bind(cancelCallbackOrContext)(arg); 39 | } 40 | } else { 41 | functionToCall(arg); 42 | } 43 | } 44 | 45 | const cachedDb = { 46 | 47 | /** 48 | * Create an 'value' on listener that will first return a cached version of the endpoint. 49 | * @param {firebase.database.Reference} dbRef Firebase database reference to listen at. 50 | * @param {Function} snapCallback Callback called when a new snapshot is available. Should return a JSON.stringify-able object that will be cached. 51 | * @param {Function} processedCallback Callback called with data returned by snapCallback, or cached data if available. 52 | * @param {Function|Object} cancelCallbackOrContext An optional callback that will be notified if your event subscription is ever canceled because your client does not have permission to read this data (or it had permission but has now lost it). This callback will be passed an Error object indicating why the failure occurred. 53 | * @param {Object} context If provided, this object will be used as this when calling your callback(s). 54 | * @returns {Promise} Resolves when the cache has been read and listener attached to DB ref. 55 | */ 56 | onValue(dbRef, snapCallback, processedCallback, cancelCallbackOrContext, context) { 57 | const storageKey = getStorageKeyFromDbRef(dbRef, 'value'); 58 | 59 | return AsyncStorage.getItem(storageKey) 60 | .then(function(value) { 61 | // Called processedCallback with cached value. 62 | if (value !== null){ 63 | var cachedVal = JSON.parse(value); 64 | callWithContext(processedCallback, cachedVal, cancelCallbackOrContext, context); 65 | } 66 | }).then(() => { 67 | var callbackPeak = function(snap) { 68 | const processed = snapCallback.bind(this)(snap); 69 | snapPeak[storageKey] = JSON.stringify(processed); 70 | processedCallback.bind(this)(processed); 71 | } 72 | dbRef.on('value', callbackPeak, cancelCallbackOrContext, context); 73 | }); 74 | }, 75 | 76 | /** 77 | * Remove any listeners from the specified ref, and save any existing data to the cache. 78 | * @param {firebase.database.Reference} dbRef Firebase database reference to clear. 79 | * @returns {Promise} Promis that will resolve after listener is switched off and cache has been written. 80 | */ 81 | offValue(dbRef) { 82 | var storageKey = getStorageKeyFromDbRef(dbRef, 'value'); 83 | 84 | //Turn listener off. 85 | dbRef.off(); 86 | 87 | return new Promise((resolve, reject) => { 88 | if(storageKey in snapPeak) { 89 | const dataToCache = snapPeak[storageKey]; 90 | delete snapPeak[storageKey]; 91 | resolve(AsyncStorage.setItem(storageKey, dataToCache)); 92 | } else { 93 | resolve(null); 94 | } 95 | }); 96 | }, 97 | 98 | /** 99 | * Create an 'child_added' on listener that will first return any cached data saved by a call to offChildAdded. When fresh data arrives, newDataArrivingCallback will be called once, followed by the standard snap callback. From this point on only the snapCallback will be called. 100 | * @param {firebase.database.Reference} dbRef Firebase database reference to listen at. 101 | * @param {*} fromCacheCallback Callback that will be called with cached data if any is available. 102 | * @param {*} newDataArrivingCallback Callback called immediately before fresh data starts arriving. 103 | * @param {*} snapCallback Callback called when new data snapshots arrive from the server. 104 | * @param {*} cancelCallbackOrContext Optional callback that will be called in the case of an error, e.g. forbidden. 105 | * @param {*} context Optional context that will be bound to `this` in callbacks. 106 | * @returns {Promise} Resolves when the cache has been read and listener attached to DB ref. 107 | */ 108 | onChildAdded(dbRef, fromCacheCallback, newDataArrivingCallback, snapCallback, cancelCallbackOrContext, context) { 109 | var storageKey = getStorageKeyFromDbRef(dbRef, 'child_added'); 110 | 111 | return AsyncStorage.getItem(storageKey) 112 | .then(function(value) { 113 | // Called processedCallback with cached value. 114 | if (value !== null){ 115 | var cachedVal = JSON.parse(value); 116 | callWithContext(fromCacheCallback, cachedVal, cancelCallbackOrContext, context); 117 | } 118 | }).then(() => { 119 | var firstData = true; 120 | 121 | var callbackIntercept = function(snap) { 122 | //Call the data arriving callback the first time new data comes in. 123 | if(firstData) { 124 | firstData = false; 125 | newDataArrivingCallback.bind(this)(); 126 | } 127 | //Then call the snapCallback as normal. 128 | snapCallback.bind(this)(snap); 129 | } 130 | 131 | dbRef.on('child_added', callbackIntercept, cancelCallbackOrContext, context); 132 | }); 133 | }, 134 | 135 | /** 136 | * Turn off listeners at a certain database.Reference, and cache the data passed in so that it can be passed to a new "child_added" listener if one is created. 137 | * @param {*} dbRef Reference to stop listening at. 138 | * @param {*} dataToCache Data that should be cached for this location. Tip: [].slice(-20) to keep the latest 20 items. 139 | */ 140 | offChildAdded(dbRef, dataToCache) { 141 | var storageKey = getStorageKeyFromDbRef(dbRef, 'child_added'); 142 | 143 | //Turn listener off. 144 | dbRef.off(); 145 | 146 | return new Promise((resolve, reject) => { 147 | resolve(AsyncStorage.setItem(storageKey, JSON.stringify(dataToCache))); 148 | }); 149 | }, 150 | 151 | /** 152 | * Wrapper around Firebase on child_removed listener. 153 | * @param {*} dbRef Database reference to listen at. 154 | * @param {*} callback A callback that fires when the specified event occurs. The callback will be passed a DataSnapshot. For ordering purposes, "child_added", "child_changed", and "child_moved" will also be passed a string containing the key of the previous child, by sort order, or null if it is the first child. 155 | * @param {*} cancelCallbackOrContext An optional callback that will be notified if your event subscription is ever canceled because your client does not have permission to read this data (or it had permission but has now lost it). This callback will be passed an Error object indicating why the failure occurred. 156 | * @param {*} context If provided, this object will be used as this when calling your callback(s). 157 | */ 158 | onChildRemoved(dbRef, callback, cancelCallbackOrContext, context) { 159 | return dbRef.on('child_removed', callback, cancelCallbackOrContext, context); 160 | }, 161 | 162 | /** 163 | * Wrapper around Firebase on child_changed listener. 164 | * @param {*} dbRef Database reference to listen at. 165 | * @param {*} callback A callback that fires when the specified event occurs. The callback will be passed a DataSnapshot. For ordering purposes, "child_added", "child_changed", and "child_moved" will also be passed a string containing the key of the previous child, by sort order, or null if it is the first child. 166 | * @param {*} cancelCallbackOrContext An optional callback that will be notified if your event subscription is ever canceled because your client does not have permission to read this data (or it had permission but has now lost it). This callback will be passed an Error object indicating why the failure occurred. 167 | * @param {*} context If provided, this object will be used as this when calling your callback(s). 168 | */ 169 | onChildChanged(dbRef, callback, cancelCallbackOrContext, context) { 170 | return dbRef.on('child_changed', callback, cancelCallbackOrContext, context); 171 | }, 172 | 173 | /** 174 | * Wrapper around Firebase on child_moved listener. 175 | * @param {*} dbRef Database reference to listen at. 176 | * @param {*} callback A callback that fires when the specified event occurs. The callback will be passed a DataSnapshot. For ordering purposes, "child_added", "child_changed", and "child_moved" will also be passed a string containing the key of the previous child, by sort order, or null if it is the first child. 177 | * @param {*} cancelCallbackOrContext An optional callback that will be notified if your event subscription is ever canceled because your client does not have permission to read this data (or it had permission but has now lost it). This callback will be passed an Error object indicating why the failure occurred. 178 | * @param {*} context If provided, this object will be used as this when calling your callback(s). 179 | */ 180 | onChildMoved(dbRef, callback, cancelCallbackOrContext, context) { 181 | return dbRef.on('child_moved', callback, cancelCallbackOrContext, context); 182 | }, 183 | 184 | /** 185 | * Twice, one better than once! Operates in a similar way to `onValue`, however `snapCallback` will only ever be called once when fresh data arrives. The value returned by `snapCallback` will be cached immediately, then passed to the `processedCallback`. If cached data is available when the listener is first turned on, it will be loaded and passed to `processedCallback`. Once data is cached then, each call to `twice` will call `processedCallback` twice, once with cached data, then once with fresh data after being processed by `snapCallback`. 186 | * @param {*} dbRef Database reference to listen at. 187 | * @param {Function} snapCallback Callback called when a new snapshot is available. Should return a JSON.stringify-able object that will be cached. 188 | * @param {Function} processedCallback Callback called maximum of twice - once with cached data, once with freshly processed data. 189 | * @param {Function|Object} cancelCallbackOrContext An optional callback that will be notified if your event subscription is ever canceled because your client does not have permission to read this data (or it had permission but has now lost it). This callback will be passed an Error object indicating why the failure occurred. 190 | * @param {Object} context If provided, this object will be used as this when calling your callback(s). 191 | * @returns {Promise} Resolves when the cache has been read and listener attached to DB ref. 192 | */ 193 | twice(dbRef, snapCallback, processedCallback, cancelCallbackOrContext, context) { 194 | const storageKey = getStorageKeyFromDbRef(dbRef, 'twice'); 195 | 196 | return AsyncStorage.getItem(storageKey) 197 | .then(function(value) { 198 | // Called processedCallback with cached value. 199 | if (value !== null){ 200 | var cachedVal = JSON.parse(value); 201 | callWithContext(processedCallback, cachedVal, cancelCallbackOrContext, context); 202 | } 203 | }).then(() => { 204 | var callbackPeak = function(snap) { 205 | const processed = snapCallback.bind(this)(snap); 206 | //Store to cache. 207 | AsyncStorage.setItem(storageKey, JSON.stringify(processed)) 208 | .then(function () { 209 | processedCallback.bind(this)(processed); 210 | }.bind(this)); 211 | } 212 | dbRef.once('value', callbackPeak, cancelCallbackOrContext, context); 213 | }); 214 | }, 215 | 216 | /** 217 | * Remove the currently cached data for a particular database.Reference. If there are any listeners still active, they will re-write their data to the cache when the .off method is called. 218 | * @param {firebase.database.Reference} dbRef Firebase database reference to clear. 219 | * @returns {Promise} Promise that resolves once all cached data for this ref has been cleared. 220 | */ 221 | clearCacheForRef(dbRef) { 222 | const location = dbRef.toString().substring(dbRef.root.toString().length); 223 | 224 | var promises = []; 225 | 226 | acceptedOnVerbs.forEach((eventType) => { 227 | const storageKey = `@FirebaseLocalCache:${eventType}:${location}`; 228 | promises.push(AsyncStorage.removeItem(storageKey)) 229 | }) 230 | 231 | return Promise.all(promises); 232 | }, 233 | 234 | /** 235 | * Remove all currently cached data. If there are any listeners still active, they will re-write their data to the cache when the .off method is called. 236 | * @returns {Promise} Promise that resolves when all cached data has been deleted. 237 | */ 238 | clearCache() { 239 | return AsyncStorage.getAllKeys() 240 | .then((keys) => { 241 | var promises = []; 242 | 243 | keys.forEach((key) => { 244 | if (key.startsWith('@FirebaseLocalCache:')) { 245 | //delete it from the cache if it exists. 246 | promises.push(AsyncStorage.removeItem(key)); 247 | } 248 | }); 249 | 250 | return Promise.all(promises); 251 | }); 252 | }, 253 | 254 | 255 | }; 256 | 257 | module.exports = cachedDb; 258 | --------------------------------------------------------------------------------