Comments (5)
I've tried to do something decidedly unusual. The behavior isn't exactly what I expected, but it's logical. I can pass in some other value that means null
for purposes of my logic that simulacra won't think of as a null value. Essentially my expectation was that I could "hijack" the change
function to override the default way that simulacra treats null
.
Thanks for your time! I'll just formulate my code differently to skirt the issue.
from simulacra.
Quote from the readme:
A change function can be determined to be an insert, mutate, or remove operation based on whether the value or previous value is null:
Value but not previous value: insert operation.
Value and previous value: mutate operation.
No value: remove operation.
You probably don't want the else clause, because that could be either an insert or update. In this case, if you want to check for insertion, it would be:
if (previousValue == null) { ... }
Is calling it the change function misleading? I wasn't too sure about the name, maybe it could be called the mapping function or something, it's only called change internally and in the docs.
from simulacra.
I apologize for the large amount of time that's passed since I said anything. To answer your question right away, I did not find the name of the change
function to be misleading.
I've written a test that shows the error more clearly: https://github.com/jakesower/simulacra/commit/8ad5faefa40392a0833e088b16eea73db477fcde
It appears to be due to having a bound variable set to null
at initialization, rather than what I initially suspected (and what you addressed). It's something of an edge case, so I intend to put in a fix and submit it as a PR.
Please let me know if the test is invalid for some reason, otherwise I'll send you a PR that makes the test pass in the coming hours/days.
from simulacra.
I think the test case is mistaken here: https://github.com/jakesower/simulacra/commit/8ad5faefa40392a0833e088b16eea73db477fcde#diff-910eb6f57886ca16c136101fb1699231R202
Since the value of change
is initialized to null
, no element is rendered initially. Consider that in terms of rendering, these states are the same:
{ simple: 'Simple', change: null }
{ simple: 'Simple', change: undefined }
{ simple: 'Simple' }
null
and undefined
values are considered to be either not renderable, or an intent to remove the corresponding element. This means that the element is non-existent for null values.
In the example on the homepage you can try:
state.details = null
and it will remove the entire element corresponding to the value.
from simulacra.
That sounds perfectly fine to do actually. I will close this now.
from simulacra.
Related Issues (20)
- Example use cases HOT 1
- Lisp rewrite HOT 2
- How to add change binding HOT 10
- Split helpers into separate build
- Rework path
- Home site simulacra.js.org does not work in IE11 HOT 3
- Data propagation from DOM to state HOT 2
- Question: detect mount of the whole component HOT 17
- TODOs
- [Homepage/Usage example]: Example not working (ReferenceError: x is not defined) HOT 2
- Merging states or flexible objects? HOT 6
- Conditional rendering example HOT 12
- More example
- JS Benchmark - Keyed Version HOT 1
- cdn example HOT 5
- How to bind to dictionary HOT 2
- IE11 table bindObject render error HOT 3
- Why does order of the bindings matter? HOT 3
- Is it safe to move DOM nodes? HOT 1
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 simulacra.