Git Product home page Git Product logo

Comments (11)

kruczy avatar kruczy commented on August 20, 2024

Hey,
Found out what's really happening

It will just call update and not create a new instance of inner component

checked what happens if component would change and it cleans the previous one though im my apps case the problem was the name of the component would be the same since I used a wrapper function, see: http://jsfiddle.net/BsUDE/12/

from domchanger.

creationix avatar creationix commented on August 20, 2024

So the problem is you're swapping out components, but since they have the same ID, it doesn't actually swap them?

from domchanger.

kruczy avatar kruczy commented on August 20, 2024

Yes it would appear so, the reason for this in my case is that I have a wrapper function around my components

Also this will be the same for browsers that don't have function.name even if you don't use a wrapper
see: https://developer.mozilla.org/pl/docs/Web/JavaScript/Reference/Global_Objects/Function/name

probably better way of comparing would be to check if it is the same function using === if I have time ill try to create a pr for this

from domchanger.

kruczy avatar kruczy commented on August 20, 2024

Managed to solve it another way, when I'm using my wrapper instead of just wrapping my component factory I wrap the whole array and set the key property to unique id of the view, now everything works perfectly

from domchanger.

creationix avatar creationix commented on August 20, 2024

Yes, setting the key property will work. That's how I've been doing it. I'm still concerned about the original issues that bit you though.

from domchanger.

creationix avatar creationix commented on August 20, 2024

I could solve this with a WeakSet of WeakMap, but that would change the minimim requirements for JavaScript significantly. (The idea is to store a weak list of all seen constructors and give each a unique ID so that they can be serialized to a string for the id algorithm.)

from domchanger.

kruczy avatar kruczy commented on August 20, 2024

The way I am thinking now would be sufficient is something like:

//define this somewhere
var constructorIdProperty = Symbol ? Symbol('domchangerId') : '_domchangerId';
//maybe just '_domchangerId' to allow users to overwrite it?
var viewId = 1;

//get the id or create one (assuming component is the factory function)
var id = component[constructorIdProperty];
if(!id) {
 id = component[constructorIdProperty] = "View" + viewId++;
}

(didn't run this so might not work)

This would allow the property to be hidden and not need more deps

from domchanger.

creationix avatar creationix commented on August 20, 2024

Ok, so stick a property on the constructor. I suppose that would work, it's just messy to annotate passed in values directly. But as you say, this does work without weakmaps.

from domchanger.

kruczy avatar kruczy commented on August 20, 2024

I don't think it is actually that bad since all browsers except IE have basic Symbol implementation so the value will not clash with anything and will be hidden from the user, though WeakMap would be nicer

only problem that can happen potentially is if someone iterates over properties of the constructor in IE and expects the value not to be there, though this can also be fixed by defining a non-enumerable property

from domchanger.

creationix avatar creationix commented on August 20, 2024

Sounds good, want to send a PR?

from domchanger.

kruczy avatar kruczy commented on August 20, 2024

sure, won't have time today, might do tomorrow though

from domchanger.

Related Issues (9)

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.