![Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack](https://cdn.sanity.io/images/cgdhsj6q/production/6af25114feaaac7179b18127c83327568ff592d1-1024x1024.webp?w=800&fit=max&auto=format)
Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
@zenchef/mobx-react-controller
Advanced tools
Readme
This project is meant to separate (pure) views from component state and lifecycle events. It is used in conjuction with mobx-react
In order to do that, There is a Controller
Component that is connected through the HoC connectController
In order to use, you need to have a component that extends Controller
Controller
extends React.Component and already defines a render method
You can add lifecycle events and regular state and methods to your controller component
The controller needs to define a method collect
that will provide props to the "dumb" view component
class MyController extends Controller {
collect() {
return {
foo: 'bar'
}
}
}
Then you need to use connectController
to connect the Controller and the View component
MyComponent = connectController(MyController)(({foo}) => {
<div>{foo}</div>
})
The View and the Controller are mobx-react observers so they will rerender if they use observable values that change
Here is a working example
import { Controller, connectController } from 'mobx-react-controller'
class HelloController extends Controller {
state = {
name: 'World'
}
changeName = () => {
this.setState({ name: 'People' })
}
collect = () => {
return {
name: this.state.name,
changeName: this.changeName
}
}
}
const HelloView = ({ name, changeName }) => {
return (
<div>
<span>Hello {name} !</span>
<button onClick={changeName}>Change Name</button>
</div>
)
}
const Hello = connectController(HelloController)(HelloView)
It works well with mobx-react's inject
method :
import { Controller, connectController } from 'mobx-react-controller'
inject('myStore')
class HelloController extends Controller {
collect = () => {
return {
name: this.props.myStore.state.name,
changeName: this.props.myStore.changeName
}
}
}
const HelloView = ({ name, changeName }) => {
return (
<div>
<span>Hello {name} !</span>
<button onClick={changeName}>Change Name</button>
</div>
)
}
const Hello = connectController(HelloController)(HelloView)
FAQs
A Component and a Decorator to separate MobX powered React Components into a Controller and View
The npm package @zenchef/mobx-react-controller receives a total of 0 weekly downloads. As such, @zenchef/mobx-react-controller popularity was classified as not popular.
We found that @zenchef/mobx-react-controller demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.