parse-community / ParseReact

Seamlessly bring Parse data into your React applications.
https://parseplatform.org
Other
1.3k stars 209 forks source link

Not able to initialize Parse a second time. #137

Closed klausbreyer closed 9 years ago

klausbreyer commented 9 years ago

Hi all,

First of all: I use react native and redux and ES6. I use my redux store to save the state to Parse:

Header require: State.js

...
var Parse = require('parse/react-native');
var ParseReact = require('parse-react/react-native');
Parse.initialize(
  CONFIG.PARSE_APPLICATION_ID,
  CONFIG.PARSE_JAVASCRIPT_KEY,
);

// somewhere in my redux reducer: 

            ParseReact.Mutation.Create('Project', {
                code: state.getIn(['projects', state.get('currentProject'), 'code']), 
                name: state.getIn(['projects', state.get('currentProject'), 'name']), 
                frames: state.get('frames'),
                athletes: state.get('athletes'),
            })
              .dispatch()
              .then(function(ob) {
                console.log('then');
                console.log(ob);
              })
              .fail(function(err) {
                console.log('error');
                console.log(err);
              });

Works. For now.

But then I added the data observable to my visual Component.

var Parse = require('parse/react-native');
Parse.initialize(
  CONFIG.PARSE_APPLICATION_ID,
  CONFIG.PARSE_JAVASCRIPT_KEY,
);
var ParseReact = require('parse-react/react-native');
var ParseComponent = ParseReact.Component(React);

...

class Field extends ParseComponent {

  observe(props, state) {
    console.log('Observieren');
    console.log(props);
    console.log(state);
    var projectOutput = new Parse.Query('Project').equalTo('code', this.state.codeInput);
    console.log('output');
    console.log(projectOutput);
    return {
      project: projectOutput
    };
  }

}

suddenly the Mutation stopped working and I receive the following stack-trace:

Error: Cannot read property '__type' of null
 stack: 
  matchesKeyConstraints      index.ios.bundle:64884
  Object.matchesQuery        index.ios.bundle:64851
  <unknown>                  index.ios.bundle:66666
  pushUpdates                index.ios.bundle:66661
  performOptimisticMutation  index.ios.bundle:66589
  Object.issueMutation       index.ios.bundle:66559
  Mutation.dispatch          index.ios.bundle:66120
  <unknown>                  index.ios.bundle:92185
  <unknown>                  index.ios.bundle:96894
 URL: undefined
 line: undefined
 message: Cannot read property '__type' of null

I could narrow it down to this:

When i Remove the Parse initialization and usage of the ParseComponent from my Component.js, the Mutation works again.

So what is the correct way to use the Parse React Native SDK in my case? Switching to es5 classes?

klausbreyer commented 9 years ago

don't know how. but this bug is gone. not sure, what i have changed. but it is not the behavior i described.