Comments (11)
It should be replacing all the handlers on each render already. Ill write a test for it and see it fails.
from deku.
Added this test for it and it's passing: a62f84a
Maybe it's something else?
from deku.
Ah interesting. Yeah maybe I need to come back at it from a new angle. Maybe it was chrome debugging that was making it seem like it? Not sure
from deku.
Hmm, will dig into it when I get back, maybe it could be when that component is nested? Doesn't seem like it, hmm
from deku.
I'm thinking it might be something to do with the component not updating because it thinks the state/props is the same. Another reason why we should use immutable.js internally :) It'll make all this way easier. I'll hack on it on the weekend.
from deku.
Mmm, yeah super weird. I think it may have something to do with how some components are wired up, gonna try more stuff, closing for now.
from deku.
Another demo of this is:
var Page = component(function(props, state){
var setState = this.setState;
var error = state.error;
// log error and change state.
function log() {
console.log(error);
setState({ error: 'Error at ' + new Date });
}
return dom('div', [
Button({
label: 'Log it',
onClick: log
})
]);
});
var Button = component(function(props){
var onClick = props.onClick;
var label = props.label;
return dom('button', { onClick: onClick }, [ label ]);
});
In there, the props in Button({ label: 'Log it', onClick: log })
never technically change between re-renders. BUT, the context of that log
function does change between renders. This seems to mean, if props include a function, they should always be considered dirty?
Basically just needs some way to diff functions.
from deku.
Weird, it looks like those scoped functions are not equal, so it should be like this:
buttonState1.props.log === buttonState2.props.log
// false
(function(){
var fns = [];
render({ text: 'first' });
render({ text: 'second' });
render({ text: 'third' });
print();
function render(props, state) {
function fn() {
return props.text;
}
fns.push(fn);
}
function print() {
console.log(' The nested functions are all not equal to each other.');
console.log()
fns.forEach(function(fn, i){
if (!i) return;
var equal = fns[i] === fns[i - 1];
console.log(' ' + equal);
});
console.log();
}
})()
The nested functions are all not equal to each other.
2 false
from deku.
Oh also wanted to mention, this can be fixed by passing in a prop that's always unique, such as:
return dom('div', [
Button({
label: 'Log it',
onClick: log,
hack: new Date
})
]);
from deku.
Looks like it's a bug in require('equals')
.
from deku.
Whoa.
In Node it's different:
(function(){
var deepEqual = require('deep-equal');
var equal = require('equals');
var fns = [];
render({ text: 'first' });
render({ text: 'second' });
render({ text: 'third' });
print();
function render(props, state) {
function fn() {
return props.text;
}
fns.push(fn);
}
function print() {
console.log(' The nested functions are all not equal to each other.');
console.log()
fns.forEach(function(fn, i){
if (!i) return;
var a = fn[i];
var b = fn[i - 1];
console.log(' a === b', a === b);
console.log(' substack/node-deep-equal (strict): ' + deepEqual(a, b, { strict: true }));
console.log(' substack/node-deep-equal: ' + deepEqual(a, b));
console.log(' jkroso/equals: ' + equal(a, b));
});
console.log();
}
})()
a === b true
substack/node-deep-equal (strict): true
substack/node-deep-equal: true
jkroso/equals: true
a === b true
substack/node-deep-equal (strict): true
substack/node-deep-equal: true
jkroso/equals: true
In the browser it's:
The nested functions are all not equal to each other.
a === b false
a === b false
Don't know about the other ones in the browser.
from deku.
Related Issues (20)
- A hard problem in the absence of context HOT 6
- State change triggered in `onRemove` method does not get rendered
- Hot module replacement docs are out of date
- "jsnext:main" in package.json isn't useful HOT 3
- Idea for window/document listeners, and possibly context/state
- displaying svg problem
- Prevent component from re-rendering on change HOT 3
- consider aliasing className HOT 2
- diff.diffNode() should return empty array when no changes
- Access DOM node in onCreate HOT 4
- Cannot npm install from github HOT 2
- Deku Override
- Provide single builded file
- 404 http://dekujs.github.io/deku HOT 5
- what happend? HOT 3
- onRemove called after DOM elements have been removed
- The first path and second path from render function unequal HOT 3
- ParseError: 'import' and 'export' may appear only with 'sourceType: module' HOT 1
- Link to docs http://anthonyshort.me/deku/ is 404 HOT 2
- Cannot read property 'forEach' of undefined
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deku.