redux#bindActionCreators JavaScript Examples

The following examples show how to use redux#bindActionCreators. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: useNotifications.js    From e-Pola with MIT License 6 votes vote down vote up
/**
 * React hook for access to notifications. Returns
 * showSuccess, showError and showMessage
 * @returns {object} Notification actions
 */
export default function useNotifications() {
  const dispatch = useDispatch()
  return useMemo(() => {
    return bindActionCreators(actions, dispatch)
  }, [dispatch])
}
Example #2
Source File: BalanceTable.js    From dexwebapp with Apache License 2.0 6 votes vote down vote up
mapDispatchToProps = (dispatch) => {
  return bindActionCreators(
    {
      showTransferModal,
      showDepositModal,
      showWithdrawModal,
    },
    dispatch
  );
}
Example #3
Source File: mapDispatchToProps.js    From Basical-react-redux-app with MIT License 6 votes vote down vote up
function mapDispatchToProps(component) {
	switch (component) {
		case "Component_1": return function (dispatch) {
			return {
				change_value_1: bindActionCreators(action_1, dispatch)
			};
		};
		case "Component_2": return function (dispatch) {
			return {
				change_value_2: bindActionCreators(action_2, dispatch)
			};
		};
		default: return undefined;
	}
}
Example #4
Source File: RestaurantTile.js    From git-brunching with GNU General Public License v3.0 6 votes vote down vote up
mapDispatchToProps = (dispatch) => bindActionCreators({
  getAll: getRestaurants,
  getPopular: getPopularRestaurants,
  getNew: getNewRestaurants,
  getOpen: getOpenRestaurants,
  select: selectRestaurant,
  changeMode: setMode,
  reset: resetBooking,
}, dispatch)
Example #5
Source File: configureStore.js    From sampo-ui with MIT License 6 votes vote down vote up
export default function configureStore (preloadedState) {
  const epicMiddleware = createEpicMiddleware()
  const middlewares = [epicMiddleware]

  // https://github.com/zalmoxisus/redux-devtools-extension#11-basic-store
  const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose

  const composedEnhancers = composeEnhancers(
    applyMiddleware(...middlewares)
    // other store enhancers could be added here
  )

  const store = createStore(reducer, preloadedState, composedEnhancers)

  epicMiddleware.run(rootEpic)

  bindActionCreators(toastrActions, store.dispatch)

  return store
}
Example #6
Source File: index.js    From strapi-molecules with MIT License 6 votes vote down vote up
export function mapDispatchToProps(dispatch) {
  return bindActionCreators(
    {
      getData,
      getDataSucceeded,
      onChangeBulk,
      onChangeBulkSelectall,
      onChangeListHeaders,
      onDeleteDataError,
      onDeleteDataSucceeded,
      onDeleteSeveralDataSucceeded,
      onResetListHeaders,
      resetProps,
      setModalLoadingState,
      toggleModalDelete,
      toggleModalDeleteAll,
      setLayout,
    },
    dispatch,
  );
}
Example #7
Source File: table-json-view-modal.js    From ThreatMapper with Apache License 2.0 6 votes vote down vote up
function mapDispatchToProps(dispatch) {
  return {
    dispatch,
    ...bindActionCreators({
      unmaskAlertRuleAction,
      closeJsonTableViewModal,
      saveClusteringRuleAction,
      maskDocsAction,
      toaster,
    }, dispatch),
  };
}
Example #8
Source File: ReminderForecastContainer.js    From jc-calendar with MIT License 6 votes vote down vote up
function mapDispatchToProps(dispatch) {
  return bindActionCreators(
    {
      getForecast: forecastUIActions.getForecast,
      resetForecast: forecastUIActions.resetForecast,
    },
    dispatch
  );
}
Example #9
Source File: connect.js    From mixbox with GNU General Public License v3.0 6 votes vote down vote up
export default function defaultConnect({actions, options}) {
    return function connectComponent(component) {
        const {
            mapStateToProps = () => ({}),
            mapDispatchToProps = (dispatch) => {
                const ac = bindActionCreators(actions, dispatch);
                Object.keys(actions).forEach(key => {
                    if (typeof actions[key] === 'object') {
                        ac[key] = bindActionCreators(actions[key], dispatch);
                    }
                });

                return {action: ac};
            },
            mergeProps,
            LayoutComponent,
        } = component;

        // 只要组件导出了mapStateToProps,就说明要与redux进行连接
        // 优先获取LayoutComponent,如果不存在,获取default
        if (mapStateToProps) {
            let com = LayoutComponent || component.default;
            if (!com) return component;
            return connect(
                mapStateToProps,
                mapDispatchToProps,
                mergeProps,
                options
            )(com);
        }
        return LayoutComponent || component.default || component; // 如果 component有多个导出,优先LayoutComponent,其次使用默认导出
    };
}
Example #10
Source File: use-actions.js    From what-front with MIT License 6 votes vote down vote up
export function useActions(actions, deps) {
  const dispatch = useDispatch();

  return useMemo(
    () => {
      if (Array.isArray(actions)) {
        return actions.map((action) => bindActionCreators(action, dispatch));
      }

      if (Object.prototype.toString.apply(actions) === '[object Object]') {
        return Object.entries(actions).reduce((bindActions, [actionName, action]) => {
          bindActions[actionName] = bindActionCreators(action, dispatch);

          return bindActions;
        }, {});
      }

      return bindActionCreators(actions, dispatch);
    },
    deps ? [dispatch, ...deps] : [dispatch],
  );
}
Example #11
Source File: BalanceHeader.js    From loopring-pay with Apache License 2.0 6 votes vote down vote up
mapDispatchToProps = (dispatch) => {
  return bindActionCreators(
    {
      showTransferModal,
      showDepositModal,
      showWithdrawModal,
      showReceiveNewModal,
    },
    dispatch
  );
}
Example #12
Source File: MovieRouteContainer.jsx    From movies with MIT License 6 votes vote down vote up
mapDispatchToProps = (dispatch) => ({
  actions: bindActionCreators({
    getDetails,
    getCredits,
    getVideos,
    getImages,
    getGenres,
    getRecomms,
  }, dispatch)
})
Example #13
Source File: AnswerForm.js    From covid19 with MIT License 6 votes vote down vote up
mapDispatchToProps = (dispatch) =>
  bindActionCreators(
    {
      deleteQuestion,
      fetchQuestions,
      setThisQuestion: setQuestion,
    },
    dispatch
  )
Example #14
Source File: mapDispatchToProps.js    From Path-Finding-Visualizer with MIT License 5 votes vote down vote up
export function whenMapDispatchToPropsIsObject(mapDispatchToProps) {
  return mapDispatchToProps && typeof mapDispatchToProps === 'object' ? wrapMapToPropsConstant(function (dispatch) {
    return bindActionCreators(mapDispatchToProps, dispatch);
  }) : undefined;
}
Example #15
Source File: GameBoard.jsx    From ashteki with GNU Affero General Public License v3.0 5 votes vote down vote up
function mapDispatchToProps(dispatch) {
    let boundActions = bindActionCreators(actions, dispatch);
    boundActions.dispatch = dispatch;

    return boundActions;
}
Example #16
Source File: DialogChangePwd.js    From college-management-react with GNU General Public License v3.0 5 votes vote down vote up
mapDispatchToProps = function(dispatch) {
  return {
    actionsUser: bindActionCreators(UserActions, dispatch)
  };
}
Example #17
Source File: analytics.js    From volt-mx-tutorials with Apache License 2.0 5 votes vote down vote up
mapDispatchToProps = dispatch => bindActionCreators({ ...marketplaceActions }, dispatch)
Example #18
Source File: ClaimsPage.js    From IBM-db2-blockchain-insurance-application with Apache License 2.0 5 votes vote down vote up
function mapDispatchToProps(dispatch) {
  return {
    claimProcessingActions: bindActionCreators(claimProcessingActions, dispatch)
  };
}
Example #19
Source File: BalanceHeader.js    From dexwebapp with Apache License 2.0 5 votes vote down vote up
mapDispatchToProps = (dispatch) => {
  return bindActionCreators({}, dispatch);
}
Example #20
Source File: LoginControl.js    From aws-workshop-colony with Apache License 2.0 5 votes vote down vote up
function mapDispatchToProps(dispatch) {
  return {
    authActions: bindActionCreators(authActions, dispatch),
    promotionActions: bindActionCreators(promotionActions, dispatch),
  };
}
Example #21
Source File: ConfirmationContainer.js    From git-brunching with GNU General Public License v3.0 5 votes vote down vote up
mapDispatchToProps = (dispatch) => bindActionCreators({
  addReservation: createBooking,
  edit: editBooking,
}, dispatch)
Example #22
Source File: Main.js    From InstagramClone with Apache License 2.0 5 votes vote down vote up
mapDispatchProps = (dispatch) => bindActionCreators({ reload }, dispatch)
Example #23
Source File: Account.js    From actual with MIT License 5 votes vote down vote up
export default function Account(props) {
  let state = useSelector(state => ({
    newTransactions: state.queries.newTransactions,
    matchedTransactions: state.queries.matchedTransactions,
    accounts: state.queries.accounts,
    failedAccounts: state.account.failedAccounts,
    categoryGroups: state.queries.categories.grouped,
    syncEnabled: state.prefs.local['flags.syncAccount'],
    dateFormat: state.prefs.local.dateFormat || 'MM/dd/yyyy',
    expandSplits: props.match && state.prefs.local['expand-splits'],
    showBalances:
      props.match &&
      state.prefs.local['show-balances-' + props.match.params.id],
    showExtraBalances:
      props.match &&
      state.prefs.local['show-extra-balances-' + props.match.params.id],
    payees: state.queries.payees,
    modalShowing: state.modals.modalStack.length > 0,
    accountsSyncing: state.account.accountsSyncing,
    lastUndoState: state.app.lastUndoState,
    tutorialStage: state.tutorial.stage
  }));

  let dispatch = useDispatch();
  let actionCreators = useMemo(() => bindActionCreators(actions, dispatch), [
    dispatch
  ]);

  let params = useParams();
  let location = useLocation();
  let activeLocation = useActiveLocation();

  let transform = useMemo(() => {
    let filter = queries.getAccountFilter(params.id, '_account');

    // Never show schedules on these pages
    if (
      (location.state && location.state.filter) ||
      params.id === 'uncategorized'
    ) {
      filter = { id: null };
    }

    return q => {
      q = q.filter({ $and: [filter, { '_account.closed': false }] });
      return q.orderBy({ next_date: 'desc' });
    };
  }, [params.id]);

  return (
    <SchedulesProvider transform={transform}>
      <SplitsExpandedProvider
        initialMode={state.expandSplits ? 'collapse' : 'expand'}
      >
        <AccountHack
          {...state}
          {...actionCreators}
          modalShowing={
            state.modalShowing ||
            !!(activeLocation.state && activeLocation.state.locationPtr)
          }
          accountId={params.id}
          location={props.location}
        />
      </SplitsExpandedProvider>
    </SchedulesProvider>
  );
}
Example #24
Source File: App.js    From Learning-Redux with MIT License 5 votes vote down vote up
mapDispatchToProps = (dispatch) => ({
  actions: bindActionCreators(TodoActions, dispatch),
})