Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate data and view (including router and react) #530

Closed
sorrycc opened this issue Jan 22, 2017 · 7 comments
Closed

Separate data and view (including router and react) #530

sorrycc opened this issue Jan 22, 2017 · 7 comments

Comments

@sorrycc
Copy link
Member

sorrycc commented Jan 22, 2017

So we can use dva with 微信小程序、支付宝小程序 and other architectures, and we can choose other router implement.

@plandem
Copy link

plandem commented Jan 22, 2017

no estimates?

@hbrls
Copy link
Contributor

hbrls commented Jan 23, 2017

As you said, dva is a framework not a library. I'd like to see it focusing on an opinionated practice.

For @plandem, if it worths to replace react-router with redux-router or else, I'd be happy to that improvement. But if it's to support both and more, the effort and concept behind is not attractive.

@sorrycc
Copy link
Member Author

sorrycc commented Jan 23, 2017

It's just do some abstraction, e.g. a library called dva-model. And the export of dva will not change, and will try to not affect the existing use of dva users.

@nihgwu
Copy link
Member

nihgwu commented Jan 23, 2017

I'm using dva in React Native and NavigationExperimantal as the router component, the only concern for me is to detach irrelevant dependencies such as react-dom and react-router.

@plandem
Copy link

plandem commented Jan 23, 2017

@hbrls yep, but there must be core concept of routing in terms of dva. E.g. at https://github.com/plandem/rrrouter I exposed next required props for any provider implementation:

	route: PropTypes.shape({ ...locationPropTypes }).isRequired,
	go: PropTypes.func.isRequired,
	back: PropTypes.func.isRequired,
	forward: PropTypes.func.isRequired,
	navigate: PropTypes.func.isRequired,

so it's up to user how he is going to implement it (e.g. at HOC). But! I know nothing about dva's routing requirements. Especially it must work via redux, so we need some kind of middleware. E.g. at: https://github.com/plandem/rrrouter-provider-redux I created one. But as I said - I need to know some specification of dva routing abstraction to integrate it at dva.

@plandem
Copy link

plandem commented Jan 23, 2017

ok, it tried to play a little with DVA (btw, sources quite hard to read. E.g.: https://github.com/d-band/fef (fork of dva) is much easier and cleaner to read).

Here are steps to make it work with my router (https://github.com/plandem/rrrouter):

import React from 'react';
import createDva from 'dva/lib/createDva';

import { createMiddleware, HashHistory, reducer as routing } from 'rrrouter-provider-redux';

export default createDva({
	mobile: false,
	initialReducer: {
		routing,
	},
	defaultHistory: new HashHistory(),
	routerMiddleware: (history) => createMiddleware(history),
	setupHistory(history) {

	},
});

and init app like this:

import './index.html';
import React from 'react';
import dva from './utils/dva';
import Router from 'rrrouter';
import { Provider } from 'rrrouter-provider-redux';

const app = dva();

const IndexPage = (props) => <div>index page</div>;
const NotFound = (props) => <div>Not Found</div>;

// 2. Model
app.model(require('./models/app'));

// 3. Router
app.router((props) =>(
	<Provider stateKey='routing' initHref='/'>
		<Router>
			<Router.Match path='/' handler={IndexPage}/>
			<Router.Miss handler={NotFound}/>
		</Router>
	</Provider>
));

// 4. Start
app.start('#root');

If remove dependency of React-Router and do some code cleanup, then I would be quite happy with current implementation.

@sorrycc sorrycc mentioned this issue Mar 27, 2017
@sorrycc
Copy link
Member Author

sorrycc commented Sep 2, 2017

Done in dva@2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants