Why wave.getState() returns NULL ?

129 views
Skip to first unread message

Setu

unread,
Jan 10, 2011, 2:07:41 AM1/10/11
to google-...@googlegroups.com
My code is : 

<?xml version="1.0" encoding="UTF-8" ?>
<Module>
    <ModulePrefs title="Random Number Generator">
        <Require feature="wave" />
        <Require feature="dynamic-height" />
    </ModulePrefs>
    <Content type="html">
<![CDATA[
        <script src="http://www.google.com/jsapi" type="text/javascript"></script>
        <script src="http://wave-api.appspot.com/public/wave.js" type="text/javascript"></script>
 <script type="text/javascript">
var content = document.getElementById('content');

function genRandomNumber(){
alert('alert');
var random_number = Math.floor(Math.random()*101);
wave.getState().submitDelta({'random': random_number});
        alert('alert');
}


function stateUpdated() {
  if(!wave.getState().get('random')) {
  alert('alert');
content.innerHTML = ""
  }
  else {
content.innerHTML = wave.getState().get('random');
  }
}

function init() {
alert('alert');
  if (wave) {
  alert('alert');
wave.setStateCallback(stateUpdated);

  }
}
gadgets.util.registerOnLoadHandler(init);
</script>
<b>Generate a random number....</b>
<div id="content" style="height: 50px;"></div>
<input type=button value="Click Me!" id="btnCount" onClick="genRandomNumber()">
]]>
    </Content>
</Module>

Zachary "Gamer_Z." Yaro

unread,
Jan 10, 2011, 10:09:18 AM1/10/11
to google-...@googlegroups.com
Are you using Firefox?  If so, there is a known issue with wave state.  If you are in Chrome or Safari, I do not know what the problem might be.

--
You received this message because you are subscribed to the Google Groups "Google Wave API" group.
To post to this group, send email to google-...@googlegroups.com.
To unsubscribe from this group, send email to google-wave-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-wave-api?hl=en.

Zachary Yaro

unread,
Jan 16, 2013, 1:43:10 AM1/16/13
to google-...@googlegroups.com
Funny enough, years later, I am now seeing this bug for the first time (in Chrome, in both Rizzoma and Wave-In-A-Box).  I know it was a while ago, but did you ever find a solution?

—Zachary “Gamer_Z.” Yaro

Serj

unread,
Jan 16, 2013, 2:42:01 AM1/16/13
to google-...@googlegroups.com
I don't think that this behavior is bug. This just means that at that moment gadget haven't receive it's state yet.

Zachary “Gamer_Z.” Yaro

unread,
Jan 16, 2013, 4:59:36 AM1/16/13
to Google Wave API
Why then would it happen in the gadgets.util.registerOnLoadHandler callback?  The impression I got is that should not fire until the gadget has been fully loaded.

—Zachary “Gamer_Z.” Yaro


--
You received this message because you are subscribed to the Google Groups "Google Wave API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-wave-api/-/sYVnqUVNzOsJ.

Serj

unread,
Jan 16, 2013, 5:37:20 AM1/16/13
to google-...@googlegroups.com
callback to gadgets.util.registerOnLoadHandler is event that notify that gadget infrastructure and it's container is ready. thus you can set handlers to perform communication with parent window: set gadget's height, get stored state
gadget wave api is also using that handler to do it's internal init:

/**
 * Internal initialization.
 */
wave.internalInit_ = function() {
  wave.checkWaveContainer_();
  if (wave.isInWaveContainer()) {
    gadgets.rpc.register('wave_participants', wave.receiveWaveParticipants_);
    gadgets.rpc.register('wave_gadget_state', wave.receiveState_);
    gadgets.rpc.register('wave_state_delta', wave.receiveStateDelta_);
    gadgets.rpc.register(
        'wave_private_gadget_state', wave.receivePrivateState_);
    gadgets.rpc.register(
        'wave_private_state_delta', wave.receivePrivateStateDelta_);
    gadgets.rpc.register('wave_gadget_mode', wave.receiveMode_);
    gadgets.rpc.call(null, 'wave_enable', null, '1.0');
  }
};

/**
 * Sets up the wave gadget variables and callbacks.
 */
(wave.init_ = function() {
  if (window['gadgets']) {
    gadgets.util.registerOnLoadHandler(function() {
      wave.internalInit_();
    });
  }
})();

at that time wave api initialize state object but it's null and then it registers to opensocial rpc listeners which will transfer state deltas, participants, etc. and only after that it will be able to receive any data

In my practice and according to wave api's asynchronous model you shouldn't perform state actions until setStateCallback is fired for state and setParticipantCallback for participants

Zachary “Gamer_Z.” Yaro

unread,
Jan 16, 2013, 11:09:45 AM1/16/13
to Google Wave API

Ah, I suppose that does make sense.  Thank you for clarifying that.

—Zachary “Gamer_Z.” Yaro

To view this discussion on the web visit https://groups.google.com/d/msg/google-wave-api/-/XRSPoc0WZCsJ.

Serj

unread,
Jan 17, 2013, 2:48:47 AM1/17/13
to google-...@googlegroups.com
I glad that I was able to explain and that someone is still trying to make interesting opensocial gadgets

Zachary “Gamer_Z.” Yaro

unread,
Jan 17, 2013, 3:00:06 AM1/17/13
to Google Wave API

Yes, it made me really happy to see someone else on this forum :)

—Zachary “Gamer_Z.” Yaro

To view this discussion on the web visit https://groups.google.com/d/msg/google-wave-api/-/RLatXuwAcmsJ.
Reply all
Reply to author
Forward
0 new messages