mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] store: dispatch method returns data from action
This commit is contained in:
committed by
Géry Debongnie
parent
a3d563ebb4
commit
10cfe0b740
@@ -39,9 +39,8 @@ export class ConnectedComponent<T extends Env, P, S> extends Component<T, P, S>
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch() {
|
dispatch(name, ...payload) {
|
||||||
const [name, ...payload] = arguments;
|
return (this.__owl__ as any).store.dispatch(name, ...payload);
|
||||||
(this.__owl__ as any).store.dispatch(name, ...payload);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1053,4 +1053,44 @@ describe("connected components and default values", () => {
|
|||||||
expect(fixture.innerHTML).toBe("<div></div>");
|
expect(fixture.innerHTML).toBe("<div></div>");
|
||||||
expect(steps).toEqual(["on:update", "off:update"]);
|
expect(steps).toEqual(["on:update", "off:update"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("dispatch an action", async () => {
|
||||||
|
env.qweb.addTemplates(`
|
||||||
|
<templates>
|
||||||
|
<div t-name="App">
|
||||||
|
<t t-esc="storeProps.counter"/>
|
||||||
|
</div>
|
||||||
|
</templates>
|
||||||
|
`);
|
||||||
|
|
||||||
|
class App extends ConnectedComponent<any, any, any> {
|
||||||
|
static mapStoreToProps = function(state) {
|
||||||
|
return {
|
||||||
|
counter: state.counter
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
counter: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
const actions = {
|
||||||
|
inc({ state }) {
|
||||||
|
return ++state.counter;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const store = new Store({ state, actions });
|
||||||
|
(<any>env).store = store;
|
||||||
|
const app = new App(env);
|
||||||
|
|
||||||
|
await app.mount(fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("<div>0</div>");
|
||||||
|
|
||||||
|
const res = app.dispatch('inc');
|
||||||
|
expect(res).toBe(1);
|
||||||
|
await nextTick();
|
||||||
|
expect(fixture.innerHTML).toBe("<div>1</div>");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user