wave.getState() returns null
- by RMorrisey
When trying to call wave.getState() in my Google Wave gadget, I get back null (no state object). How can I initialize the Wave state object? I am working in the Wave Sandbox.
My ModulePrefs contains the following:
<Require feature="wave" />
<Require feature="rpc"/>
I got the "rpc" feature from some google groups post when searching for a fix, but it doesn't seem to be any help.
The gadget contains a jQuery plugin, which defines the classes I use (not shown), attaches an event handler to the link that shows up in edit mode, and sets up the callback methods with the google wave gadget initializer:
$.fn.extend({
$.gork.InitPass.newButtonClick = function newButtonClick() {
var jer = new $.gork.InitPass.Player('Jeremias', 12, 2);
var delta = {};
delta[jer.name] = jer.serialize();
wave.getState().submitDelta(delta);
};
$.gork.InitPass.modeCallback = function modeCallback() {
var state = wave.getState();
var mode = wave.getMode();
$.gork.InitPass.getContainer().ipCombatState(state, (mode == wave.Mode.EDIT));
};
$.gork.InitPass.stateCallback = function stateCallback() {
$.gork.InitPass.getContainer().ipCombatState(
wave.getState(), (wave.getMode() == wave.Mode.EDIT));
alert('state');
};
$.gork.InitPass.init = function init() {
if (wave && wave.isInWaveContainer()) {
var mode = wave.getMode();
$('.gork-ip-container').ipCombatState(null, (mode == wave.Mode.EDIT));
wave.setModeCallback($.gork.InitPass.modeCallback);
wave.setStateCallback($.gork.InitPass.stateCallback);
}
};
})(jQuery);
gadgets.util.registerOnLoadHandler($.gork.InitPass.init);
$(function ready() {
$.gork.InitPass.getContainer().find('.gork-ip-edit .addSection a.newButton').click(
$.gork.InitPass.newButtonClick);
});
So there are two main pieces of functionality here:
When the mode changes, ipCombatState(...) is called. This changes the visual appearance of the gadget when the user puts the gadget in Edit mode (CTRL+E), by hiding the view DIV and displaying the edit DIV.
The newButtonClick callback (which is attached to the link "a.newButton" in the edit container) is supposed to add Jeremias (Nate's Shadowrun character) to the gadget state, so that he'll be appear as a table row in edit mode.
I have verified that the initializer method is called, and the view/edit mode switch works just fine (except the state is null). When I click on the new button link (the link at the bottom in edit mode), and trigger the newButtonClick handler, I get an error because wave.getState() also returns null.
How can I initialize the wave state so that I can work with it?
The purpose of my gadget will be to keep track of combat initiative order in a Shadowrun tabletop game (4th Ed). You can test it out in Wave and see what I have so far:
http://gorkwobble.herobo.com/wave/init-pass.xml
The actual javascript code is externalized to:
http://gorkwobble.herobo.com/wave/init-pass.js
P.S. If any Shadowrun players read this, and want to hear about it when I get the gadget working, leave a comment and I'll wave you.