Code Monkey home page Code Monkey logo

Comments (11)

anthonyshort avatar anthonyshort commented on May 27, 2024

It should be replacing all the handlers on each render already. Ill write a test for it and see it fails.

from deku.

anthonyshort avatar anthonyshort commented on May 27, 2024

Added this test for it and it's passing: a62f84a

Maybe it's something else?

from deku.

lancejpollard avatar lancejpollard commented on May 27, 2024

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.

lancejpollard avatar lancejpollard commented on May 27, 2024

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.

anthonyshort avatar anthonyshort commented on May 27, 2024

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.

lancejpollard avatar lancejpollard commented on May 27, 2024

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.

lancejpollard avatar lancejpollard commented on May 27, 2024

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.

lancejpollard avatar lancejpollard commented on May 27, 2024

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.

lancejpollard avatar lancejpollard commented on May 27, 2024

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.

lancejpollard avatar lancejpollard commented on May 27, 2024

Looks like it's a bug in require('equals').

from deku.

lancejpollard avatar lancejpollard commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.