Boiling React Down to Few Lines in JQuery
hackflow.com
Boiling React Down to Few Lines in JQuery
1–10 of 35 posts
Re: Boiling React Down to Few Lines in JQuery
#2It's also a philosophy of UI composition. It's also a philosophy of data consumption. It's also a philosophy of code structure.
Having written my share of code with both, I now prefer composing UI's in React. It's easier to get simpler code maintenance and better performance with React.
Re: Boiling React Down to Few Lines in JQuery
#3I don't think this is good advice. It would be better to just start by using something like React, then if things get too slow, implement shouldComponentUpdate, because you will almost certainly need something that can make efficient DOM updates instead of just naively recreating whole DOM trees.
Re: Boiling React Down to Few Lines in JQuery
#4React is more than a few lines of clever Javascript. It's also a philosophy of UI composition. It's also a philosophy of data consumption. It's also a philosophy of code structure. Having written my share of code with both, I now prefer composing UI's in React. It's easier to get simpler code maintenance and better performance with React.
Re: Boiling React Down to Few Lines in JQuery
#5Example:
function MyComponent(element) {
var instance = this;
instance.element = element;
instance.history = [];
instance.state = { myKey: 'someData' };
instance.template = _.template($('my-template').html());
instance.setupHandlers();
}
MyComponent.prototype.render = function() {
var instance = this;
instance.element.html(instance.template(instance.state));
instance.history.push(deepcopy(instance.state));
}
MyComponent.prototype.undo = function() {
var instance = this;
instance.state = instance.history.pop();
instance.render();
}
MyComponent.prototype.setupHandlers = function() {
instance.element.on('change', '.my-input', function(e) {
instance.state.myInput = $(this).val();
instance.render();
});
}
This is of course a very simplified version but it should give you an idea of what I'm talking about.Re: Boiling React Down to Few Lines in JQuery
#6Re: Boiling React Down to Few Lines in JQuery
#7I use something a little similar where I work. No one would be on board with something like React but I've documented a way to write our code that does something similar to this post. We use js "classes" (Both Function.prototype and now js classes with babel) and lo-dash templates to make it a little nicer. Example: function MyComponent(element) { var instance = this; instance.element = element; instance.history = []…
Re: Boiling React Down to Few Lines in JQuery
#8Re: Boiling React Down to Few Lines in JQuery
#9React is more than a few lines of clever Javascript. It's also a philosophy of UI composition. It's also a philosophy of data consumption. It's also a philosophy of code structure. Having written my share of code with both, I now prefer composing UI's in React. It's easier to get simpler code maintenance and better performance with React.
Re: Boiling React Down to Few Lines in JQuery
#10I use something a little similar where I work. No one would be on board with something like React but I've documented a way to write our code that does something similar to this post. We use js "classes" (Both Function.prototype and now js classes with babel) and lo-dash templates to make it a little nicer. Example: function MyComponent(element) { var instance = this; instance.element = element; instance.history = []…
There are other issues such as event delegation,cleaning up event listeners,... that will make your solution hard to scale past simple widgets.And before you know it,you'll be writing your own complicated framework that does less than Angular or React.