GithubHelp home page GithubHelp logo

redux-history-transitions's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

redux-history-transitions's Issues

Making this library router agnostic and only dependent on `history`

With the advent of react-router 1.0 there have been great API improvements. For this project the main part is that the user can now provide a history instance to the router. Since the history object is not specific to react-router and can be used with any type of router, the current library name isn't fitting anymore. I am proposing to rename this from redux-react-router-transitions to redux-history-transitions in order to make clear that this library works with any system which uses a history instance to manage url-state.

Furthermore the use of history introduces breaking changes. Originally you were able to return an object with a shape of { path, params, query, replace } and the library would then utilize react-router to merge params into path and append query as query-string.

This shape has changed and now looks like this: { path, query, replace, state }. This means that instead of returning a path like /some/path/:myParam, you now will use template strings to inject the params directly: /some/path/${myParamVar}. In order to use query strings, you will have to enhance the history object with the useQueries enhancer. How this works can be seen in the example project.

All in all what this means is that redux-history-transitions now can be used whether you are using react or angular or whatever view library/framework you prefer, as long as you use history to manage your urls. This also means that I will be dropping support for react-router 0.13

The code in the master branch is updated and a working example is provided.

I would love to hear some opinions about this (suggestions to improve the API are also welcome!).
I personally feel that this is the way to go.

/cc @gaearon @idolize

Introduce more specific transition functions, i.e. they are only called on `success` or `failure`

Currently the transition function gets called all the time and the consumer has to decide whether to return anything depending on the state of the action. This boilerplate should be moved into the library.

Currently:

meta: {
  transition: (prevState, nextState, action) => { ... }
}

Next version:

meta: {
  transition: {
    // catch-all handler which gets called for each
    // action state (begin and success/failure)
    onAction: (prevState, nextState, action) => { ... }

    // gets only called for a successful async action
    onSuccess: (prevState, nextState, action) => { ... },

    // gets only called for a failed async action
    onFailure: (prevState, nextState, action) => { ... }
  }
}

URL replaced but transition not happening

I'm running into a weird issue where the URL changes when i use a meta attribute with a transition in my actions but the view does not actually change.

My configureStore() method looks like this:

import { compose, applyMiddleware, createStore } from 'redux'
import { persistStore, autoRehydrate } from 'redux-persist'
import { localStorage } from 'redux-persist/storages';
import thunkMiddleware from 'redux-thunk'
import { createLogger } from 'redux-logger'
import handleTransitions from 'redux-history-transitions';
import createHistory from 'history/createBrowserHistory'
import { routerMiddleware } from 'react-router-redux'

import reducers from '../reducers'

const loggerMiddleware = createLogger()

export default function configureStore() {
  const history = createHistory()
  const enhancer = handleTransitions(history)
  
  const store = createStore(
    reducers,
    undefined,
    compose(
      applyMiddleware(
        thunkMiddleware,
        loggerMiddleware,
        routerMiddleware(history),
      ),
      enhancer,
      autoRehydrate()
    )
  )

  // begin periodically persisting the store
  persistStore(store, { storage: localStorage })

  return store;

}

And my action looks like this:

function addedDish(restaurantID, json) {
  return {
    type: NEW_DISH,
    dish: json,
    restaurantID,
    receivedAt: Date.now(),
    meta: {
      done: true,
      transition: {
        success: (prevState, nextState, action) => ({
          pathname: `/${restaurantID}/dishes/${action.dish.id}/`,
        }),
      },
    },
  }
}

The dish is added, the action triggered, and the URL changes, but the view is not re-rendered. 'normal' react-router changes triggered with Link or Redirect do work as expected.

Did i misconfigure the enhancer somehow or should i look elsewhere for the culprit?

Async action

Hi

Is this able to handle an async action?

thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.