hjertnes.blog

#

11.01.2018 01:00

Is VIM 8 ’s native “package manager” really a package manager?

#

11.01.2018 01:00

#

11.01.2018 01:00

#

11.01.2018 01:00

Am I such a pin whore that I actually add a reoccurring task called “Post to Micro.blog” to todoist to get that “Daily Blogger” pin?

#

11.01.2018 01:00

MobX

11.01.2018 01:00

I have never built anything with MobX, and I don’t think I will, unless it’s forced down over my head. But I’m pretty sure that if I had the choice between a job where I worked with redux or one where I worked with MobX, I would have chosen the former; much like I would have if I had the option between a job where I used React and one where I used Vue or Angular.

I’m not sure how it makes stuff easier, but it does at least move state management out of your components. Look here if you want a sample project / tutorial.

If you think functional programming isn’t your thing, or something like that I would look at MobX. One of the things I have heard about MobX is that it requires less code than redux. But I don’t see anything in MobX that lets you place the state anywhere in the component three like you can with redux. And the whole decorator thing feels a little bit too much like Java programming for my taste.

I don’t mind Java or C# as a backend language, but I don’t think those ideas are that great when it comes to frontend development.

It might be the right thing for you, even though I don’t like it; especially if you don’t like redux.

#

10.01.2018 01:00

#

10.01.2018 01:00

Just deleted the 500px and Instagram apps

#

10.01.2018 01:00

What kind of read it later service / app are you using?

Redux Example

10.01.2018 01:00

A Redux Store consists of a few different parts. You always have a single store, that uses either a single Reducer or Multiple Reducers (through Redux’s CombineReducers method). And you dispatch actions to your reducers. (You also have the initial state for each reducer, that is the default values)

  • Store = is like an instance of a class. It contains the actual data.

  • A reducer takes the current state + an action, applies it to the state and returns the new state.

If you look in the gist above you see everything you need to set up a basic redux setup. You can make it how simple or complex you want to. I personally just make multiple reducers, and action-creator methods that update them.

The awesome thing about redux is that it isn’t a “react thing”. This means that you could use the same state layer with any front end library or framework.

If you want to use it with react then you need two things from the the react-redux package: Provider and Connect.

You place the around the JSX code in your ReactDOM render() method in your entry point. And then you use the connect() method to map functions and state elements to your components.

You map state elements to your components so that what is in redux are passed as props to your components, and you map your action creators to your component through connect so that the action creators have access to your store’s dispatch method.

Something like this:

As usual, the code above is working, but you need to add some imports etc to have a working example.