Comments (6)
Being someone who works w/ Angular on a daily basis, I know exactly what you mean, but I'm not much of a fan of adding code to core to support a specific debugging use case. My experience with that technique is that sooner or later you end up forgetting a debug expression in the view and embarrassment ensues.
The easy way to do what you want is to just wrap it in a console.log (or console.dir, or whatever you prefer):
m("div", [
debugObject().property, // will print properly
console.log(debugObject()) //returns undefined, but also prints properly
])
It's a bit more explicit and less magic, but as I mentioned elsewhere, I'd rather avoid magic.
from mithril.js.
With that being said, this does raise an issue that passing an arbitrary object into a virtual element tree as if it were a virtual element throws non descriptive errors, so I'll flag this as a bug
from mithril.js.
wrapping the debugObject() in a console.log throws this error though: Uncaught TypeError: Cannot read property 'nodes' of undefined
console.log is a unit function so it returns an undefined, and so in this particular case, the children of the div evaluate to ["string", undefined]
, and it doesn't seem to handle printing undefined
.
The only case I can think of that can make this work is
m("div", [
function(){
console.log(debugObject());
return debugObject().property;
}
])
And that's just... unwieldy.
from mithril.js.
Uncaught TypeError: Cannot read property 'nodes' of undefined
Oh, that's a serious bug. Will fix this as soon as I get a chance.
Assuming it does get fixed, does the inline console.log seem reasonable to you, @levitanong ?
from mithril.js.
Definitely! Most certainly will be cleaner than what I've been doing with angular.
from mithril.js.
The null reference error when passing undefined
as a node in a virtual dom tree is now fixed in the origin/next branch and is scheduled to be released in v0.1.1. As a side effect, putting arbitrary objects in a virtual dom tree no longer throws errors either (they just get ignored).
from mithril.js.
Related Issues (20)
- Why are v.attrs passed to oninit() for a child component an empty object? HOT 5
- There is no onsize/onresize lifecycle method HOT 4
- Typescript return type for mithril components HOT 14
- warning 'reuse attrs object' while receiving a component from high order function/component HOT 4
- Broken link to ospec in API page
- make vite the default HOT 4
- Redraw on resolve of async event handler HOT 1
- Please update the Vue comparison HOT 1
- onbeforeremove not being triggered when list element is removed HOT 2
- Form attribute not set in custom element HOT 1
- Add "main" field to package.json
- Need help with "Failed to execute 'insertBefore' on 'Node'" errors. HOT 2
- Is there a bug with dynamically changing svgs? HOT 15
- Current vnode `dom` property is undefined in `onbeforeupdate` HOT 4
- Not getting any events to handle resize HOT 1
- Been a while since the last commit, is Mithril complete? or abandoned? HOT 13
- We have both `main` and `master`. Let's drop both and just rely on a global `next` + version-specific `next`s. HOT 2
- JSFiddle links are broken in CI HOT 2
- htm with Mithril.js HOT 3
- Deprecated dependencies `inflight` and `glob`
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 mithril.js.