Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Error when used with React Native. StoreType= Memory #151

Open
veenedu opened this issue May 9, 2016 · 7 comments
Open

Error when used with React Native. StoreType= Memory #151

veenedu opened this issue May 9, 2016 · 7 comments
Assignees
Labels

Comments

@veenedu
Copy link

veenedu commented May 9, 2016

I am planning to use it with react native, as in Memory dataEngine.

I am getting error just in importing the file in both android and iOs. Platforms.

import lf from 'lovefield'

this is the only line of code I have written.

screen shot 2016-05-09 at 1 58 02 pm

screen shot 2016-05-09 at 1 58 47 pm

@freshp86
Copy link
Contributor

freshp86 commented May 9, 2016

I am not familiar with React, but the problem seems to be coming from the 1st line in lovefield.min.js, see https://github.com/google/lovefield/blob/master/dist/lovefield.min.js#L1. I suggest exploring a bit what makes it blow up (maybe comment out the 1st and last line of lovefield.min.js and retry).

As explained at https://github.com/google/lovefield/blob/master/docs/FAQ.md#can-lovefield-be-used-with-angularbootstrapcordovad3-, we can't possibly ensure that Lovefield works with all JS frameworks, but we will consider a PR/suggestion.

@arthurhsu
Copy link
Contributor

The clean up is needed for detecting self in a better way. self is not a standard thing.

@bimusiek
Copy link

bimusiek commented Aug 2, 2016

I have configured lovefield properly with React + WebPack. Soon I will post some details how but basically:

  1. I use SPAC to generace code from schema.
  2. I pull all lovefield source code and do on it npm install so it gets all libs.
  3. Then I use google closure compiler to generate one file with my schema file, lovefield and closure library.
java -jar ${SCRIPTPATH}/../tools/lovefield/node_modules/google-closure-compiler/compiler.jar --dependency_mode=STRICT --entry_point='ahoydb.row.FlightBooking' --js_output_file=${SCRIPTPATH}/../app/libs/database/ahoydb.js "${SCRIPTPATH}/../tools/lovefield/node_modules/google-closure-library/**.js" '!**_test.js' "${SCRIPTPATH}/../tools/lovefield/lib/**.js" "${SCRIPTPATH}/../app/libs/database/lovefield/**.js"

And later if you use webpack, you can import it like this:

const db = require('imports?this=>window!exports?ahoydb&lf!./ahoydb')

Where db.lf is lovefield and db.ahoydb is methods you use for connecting. (ahoydb comes from your database name in schema file)

@arthurhsu
Copy link
Contributor

Assign to freshp86@. The self thing is added for the fix of #144, which handles that situation but not this one and #189.

I'd suggest to do if(self && !self.window){window=self;} in the wrapper flag stead. But I have no idea how that was tested in the first place.

@freshp86
Copy link
Contributor

freshp86 commented Jan 6, 2017

Digging through the history, the wrapper had been modified to fix #33, see commit 599f5d9.

I don't remember much more about it than what is in the above links. Would have to play with React to figure out if there is a way to satisfy all use cases (webworker, browserify, React etc).

@veenedu
Copy link
Author

veenedu commented Jan 7, 2017

@freshp86 You don't have to play with react and others.
If below code could work in node environment this issue will get resolved. self is not defined is the issue and I know there is a hack for this

import lf from 'lovefield';

or

var lf = require('lovefield')

I am using tools/node_bootstrap to include lovefield in my react native app.

For persistance I am using data type lf.schema.DataStoreType.WEB_SQL with Sqlite as storage.

React Native developers prefer Realm.io but I chose lovefield as its really fast compared to Realm.io

@bitlab-code
Copy link

bitlab-code commented Oct 27, 2019

@veenedu currently directly use node_bootstrap in RN throw errors, can you share more about how you made it work

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants