Comments (11)
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.
So the problem is you're swapping out components, but since they have the same ID, it doesn't actually swap them?
from domchanger.
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.
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.
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.
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.
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.
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.
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.
Sounds good, want to send a PR?
from domchanger.
sure, won't have time today, might do tomorrow though
from domchanger.
Related Issues (9)
- DomChanger Redux Connect HOT 1
- Server-side render HOT 9
- if the render data wil cause no render.
- Typescript support
- Publish to NPM? HOT 2
- diffing bug? HOT 8
- after render hook? HOT 10
- more isolated/stateful components HOT 16
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 domchanger.