Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
mobservable
Advanced tools
Mobservable is a library to create reactive state and views. Mobservable updates views automatically when the state changes, and thereby achieves inversion of control. This has major benefits for the simplicity, maintainability and performance of your code. This is the promise of Mobservable:
Elegant! I love it! ‐ Johan den Haan, CTO of Mendix
We ported the book Notes and Kanban examples to Mobservable. Check out the source to see how this worked out. Compared to the original I was definitely positively surprised. Mobservable seems like a good fit for these problems. ‐ Juho Vepsäläinen, author of "SurviveJS - Webpack and React" and jster.net curator
Great job with Mobservable! Really gives current conventions and libraries a run for their money. ‐ Daniel Dunderfelt
I was reluctant to abandon immutable data and the PureRenderMixin, but I no longer have any reservations. I can't think of any reason not to do things the simple, elegant way you have demonstrated. ‐David Schalk, fpcomplete.com
Mobservable can be summarized in two functions that will fundamentally simplify the way you write React applications. Lets take a look at this really really simple timer application:
var timerData = {
secondsPassed: 0
};
setInterval(function() {
timerData.secondsPassed++;
}, 1000);
var Timer = React.createClass({
render: function() {
return (<span>Seconds passed: { this.props.timerData.secondsPassed } </span> )
}
});
React.render(<Timer timerData={timerData} />, document.body);
So what will this app do? It does nothing! The timer increases every second, but the will UI never update. To fix that, we should force the UI to refresh somehow upon each interval. But that is the kind of dependency we should avoid in our code. We shouldn't have to pull data from our state to update the UI. Instead, the data structures should be in control and call the UI when it needs an update. The state should be pushed throughout our application. This is called inversion of control.
We can apply two simple functions of Mobservable to achieve this.
The first function is makeReactive
. It is the swiss knife of mobservable and turns any data structure and function into its reactive counterpart. Objects, arrays, functions; they can all be made reactive. Reactiveness is contagious; new data that is put in reactive data will become reactive as well. To make our timer reactive, just change the first three lines of the code:
var timerData = mobservable.makeReactive({
secondsPassed: 0
});
The second important function is reactiveComponent
from the mobservable-react
package. It turns a Reactjs component into a reactive one, that responds automatically to changes in data that is used by its render method. It can be used to wrap any react component, either created by using ES6 classes or createClass
. So to fix the example, just update the timer definition to:
var Timer = mobservableReact.reactiveComponent(React.createClass{
/** Omitted */
}));
Its as simple as that. The Timer
will now automatically update each time timerData.secondsPassed
is altered.
The actual interesting thing about these changes are the things that are not in the code:
setInterval
method didn't alter. It still treats timerData
as a plain JS object.Timer
component would be somewhere deep in our app; only the Timer
would be re-rendered. Nothing else.All this missing code... it will scale well into large code-bases! It does not only work for plain objects, but also for arrays, functions, classes, deeply nested structures.
npm install mobservable --save
.npm install mobservable-react --save
as well. You might also be interested in the dev tools for React and Mobservable.Fresh step-by-step documentation is coming soon!
For the full api, see the API documentation.
This is an overview of most important functions available in the mobservable
namespace:
makeReactive(value, options?) Turns a value into a reactive array, object, function, value or a reactive reference to a value.
reactiveComponent(reactJsComponent)
Provided by the mobservable-react
packaege, turns a ReactJS component into a reactive one, that automatically re-renders if any reactive data that it uses is changed.
extendReactive(target, properties) Extends an existing object with reactive properties.
sideEffect(function)
Similar to makeReactive(function)
. Exception the created reactive function will not be lazy, so that it is executed even when it has no observers on its own.
Useful to bridge reactive code to imperative code.
transaction is used
)FAQs
Observable data. Reactive functions. Simple code.
The npm package mobservable receives a total of 13 weekly downloads. As such, mobservable popularity was classified as not popular.
We found that mobservable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.