Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access store from component

i have a component and when user click on component it add some value to store,i try to use this way but i get an error :

OlapApp.MeasureListItemComponent = Ember.Component.extend({   tagName: 'li',   isDisabled: false,   attributeBindings: ['isDisabled:disabled'],   classBindings: ['isDisabled:MeasureListItemDisabled'],    actions: {     add: function(measure) {       var store = this.get('store');       store.push('OlapApp.AxisModel', {             uniqueName: measure.uniqueName,             name: measure.name,             hierarchyUniqueName: measure.hierarchyUniqueName,             type: 'row',             isMeasure: true,             orderId: 1       });     }   } }); 

and this is error:

Uncaught TypeError: Cannot call method 'push' of undefined  MeasureListItemComponent.js:18 

is it posible to push record to store from component? why i cant access to store ? my model name is 'AxisModel' and application namespace is 'OlapApp'

like image 399
MBehtemam Avatar asked Sep 04 '13 11:09

MBehtemam


People also ask

How do you access the store in child component React?

It's simple to get access to the store inside a React component – no need to pass the store as a prop or import it, just use the connect function from React Redux, and supply a mapStateToProps function that pulls out the data you need. Then, inside the component, you can pass that data to a function that needs it.

How do I access Redux store in React?

Understanding Context Usage​ createContext() , called ReactReduxContext . React Redux's <Provider> component uses <ReactReduxContext. Provider> to put the Redux store and the current store state into context, and connect uses <ReactReduxContext. Consumer> to read those values and handle updates.

How can we access a Redux store outside a React component?

To access the store in non-component front end code, I used the analogous import (i.e., import {store} from "../../store. js" ) and then used store. getState() and store.

How do I get a store state in Redux?

You need to use Store. getState() to get current state of your Store.


1 Answers

Since Ember v1.10, the store can be injected to components using initializers, see: http://emberjs.com/blog/2015/02/07/ember-1-10-0-released.html#toc_injected-properties:

export default Ember.Component.extend({     store: Ember.inject.service() }); 
like image 94
Jacob van Lingen Avatar answered Oct 14 '22 03:10

Jacob van Lingen