Comments (17)
@mindplay-dk I'm sorry, now fre's key is not valid for components, and only ordinary element's key is currently supported.
I've got a new idea here recently, and it's likely to come true soon.
Or do you have any suggestions?
from fre.
Well, missing support for key
probably should be tracked in a separate issue.
The main issue with this example is the DOM getting scrambled when main App
component updates - that happens even if you remove the key
attribute from the example.
from fre.
Halo, I've fixed this case now, and now It can get the correct rendering, but the diff result is still not the smallest.
I've been busy in class recently. Please give me more time.
import { h, render, useState } from 'fre'
function App () {
const [arr, setArr] = useState(1)
return (
<div>
{new Array(arr).fill().map(i => (
<A val={i} key={i}/>
))}
<button onClick={() => setArr(arr+1)}>+</button>
</div>
)
}
function A (props) {
const [count, setCount] = useState(0)
return (
<div>
{count}
<button onClick={() => setCount(count + 1)}>+</button>
</div>
)
}
render(<App />, document.body)
Or Could we study diff under fiber together?
from fre.
I tried updating my example to 1.5.5
, but I can't get the package to load at all now.
For example, if I do this:
import * as fre from "fre";
console.log(fre);
All I see in the console is { default: {} }
.
It seems nothing is exported. The module build is maybe broken somehow?
from fre.
@mindplay-dk I found some bugs in my diff scheme again. I will write a new diff scheme during the holidays. Thank you for your use case.
from fre.
Ah ah! I found a JSX black magic to help solve this problem.
Please wait for my code pushing this weekend~
from fre.
Rewrite the diff schema, fix this case, upgrade to the latest version.
from fre.
The module works again - but now the elements aren't getting ordered correctly:
Also, the disabled
-attribute on the "Remove" button doesn't seem to update anymore.
You can fork/test my example for yourself here:
https://codesandbox.io/s/determined-butterfly-uxuic
(You should probably think about adding at least a basic test-suite - complex things like these have a tendency to break very easily, even with small changes. It can be very difficult to manually test for every possible thing that could break.)
from fre.
@mindplay-dk Agree. I have to admit that diff of the fiber list is really difficult. The main obstacle is the traversal of linked list.
I need more time to study it carefully. No other libraries have similar logic expect React, that makes it difficult for me to emulate.
Please wait for my reply, thanks!
from fre.
You're brave for even attempting this 💪😁
from fre.
@mindplay-dk Hey ~ I'm on vacation now. I've refactor a new version. It looks like it can solve the problem now.
This is not necessarily true, but the current way should be correct!
from fre.
Works better now, components get created/destroyed and maintain state correctly. 👍
There's one problem remaining in my example though: the disabled
property on the "Remove" button isn't being updated.
Looks like two things are missing here:
-
You're mapping props to
setAttribute()
calls, which only works for HTML attributes, which is not the same as object properties - for example,dom.disabled
is aBoolean
property, whereasdom.setAttribute("disabled", value)
expects astring
value; HTML attributes are always strings. -
You only set attributes - you need to also be able to remove them.
You can see examples of both here. (Note that this implementation tracks whether a target element is an SVG node or not - something you may need to do later, if you want to support SVG. For reference, see also Preact's implementation here.)
from fre.
Ah……you're right. It's my oversight. I'm going to fix it and support svg, too.
from fre.
I fixed this and supported SVG…… but the size now reached 2kb!So sad 😢
from fre.
2 KB for something like this is extremely good - focus on ensuring the project's integrity (tests!) and worry about optimizing for size later, when it's safe to do so. Refactoring for size at this stage, without tests, is extremely risky.
Do you have a preference for a test-framework? I see you have jest
in there, so I might try to help out and get some basic tests going. 🙂
from fre.
I really like testing framework T_T. but I'm not very good at it, but I think it's necessary.
Thank you very much !
from fre.
I've confirmed the fix in 1.6.0
👍
I'm closing this issue, thanks! (Let's continue the discussion about tests elsewhere.)
from fre.
Related Issues (20)
- 该段 JSX 在首次渲染视图时可能出错 HOT 1
- Uncaught DOMException: Failed to execute 'insertBefore' on 'Node': This node type does not support this method. HOT 2
- useState bug HOT 1
- true instead of ture HOT 3
- demo 最新的master上不能用了
- demo 最新的master上不能用了 HOT 1
- 😄 HOT 5
- 能否抽空增加源码注释 HOT 6
- Support for new React 18 hook - useSyncExternalStore HOT 2
- 请问支持ssr吗 HOT 3
- useState and useReducer dispatch unstable between renders HOT 5
- batchedUpdates? HOT 1
- When render is called multiple times HOT 3
- Funny rendering results: when rendering a list, if the expressions are not wrapped in tags alone like <div>{list.map..}</div>, may cause a funny render. HOT 2
- Support useTransition/startTransition/Suspense? HOT 1
- XiaoHeShang-NMSL HOT 1
- 渲染 10w 个节点,对比 fre、vue、react HOT 2
- 记录一些问题
- [Question] useState 为何无函数式初始化方式 HOT 5
- [Bug] useRef 莫名丢失透传参数,memo失效 HOT 2
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 fre.