Comments (17)
@nichoth By the way, HyperApp is also all ES5, no build tools required. We're using rollup to generate the UMD bundles that users grab when embedding via an <script>
tag, but that's another thing.
EDIT: BTW, I tried to see what's in https://github.com/nichoth/model-message, but it's 404ing.
from hyperapp.
Yeah sounds good. I have been experimenting more with different APIs. I made a traditional todomvc with pull-streams, which I like. https://github.com/nichoth/todomvc-pull-stream . The important part is pull-stream-model, which provides some structure/convention.
So main thing was to find a nice way of writing tests, which I still haven't gotten around to, but will soon. In this case we are adding tests to an existing large app that doesn't have any.
The idea is that all the app events we care about are serialized to static objects that can be logged. So in the todo app, https://github.com/nichoth/todomvc-pull-stream/blob/master/app.js#L33 , you can log events at any point in the pipeline. We want to log them after any async operations, since that introduces randomness. In the example it's just the browser console, but in real life we have a small utility that sends events to a websocket server that logs them. Then you can replay the log in an automated way and check that the events are valid and the resulting state is ok.
from hyperapp.
Sounds like mad science :) π
from hyperapp.
Oh! I didn't realize that about es version β that's important. I think the titles of the PRs threw me off π . btw, I fixed the package.json so it has the right repo
from hyperapp.
The es6 was a false alarm :). The thing I would really like to solve is finding an easy way to run automated tests on browser applications. I'm not an expert with elm β I don't know how tests work β but compile time type checking would catch a majority of the bugs I have day to day. JS is in a weird place where unit tests often fill the role of type checking. My interest in decoupling model & view is because I'm trying to find a way to easily write automated app tests. One idea is to declare all the events as data (the .msg
object), so we can easily test the model against the events with mock input. I'm just kind of thinking out loud here, would be interested in hearing what other's experiences are like.
from hyperapp.
Do you mean HyperApp tests or your app's tests?
from hyperapp.
@jbucaran I mean my app's tests (tests of the application code, not the dependencies). So my-app
would consume hyperapp
, for example, and we need to test my-app
, which is not a dependency of anything. Dependencies are easier because the interface is not a UI via the dom.
It is totally possible to write automated tests for an application⦠but the amount of (tedious) labor required can be prohibitive.
from hyperapp.
My interest in decoupling model & view
ELI5, what do you mean by decoupling in this context and how does it apply to HyperApp?
I ask, because I see that in your Counter
example, you've split the application into counter.js
and app.js
, but you can do the same in HyperApp from day one.
app.js
const { app } = require("hyperapp")
const Counter = require("./counter")
app(Counter)
counter.js
const { html } = require("hyperapp")
module.exports = options => ({
model: options.initialCount,
update: {
add: model => model + 1,
sub: model => model - 1
},
view: (model, msg) => html`
<div>
<button onclick=${msg.add}>+</button>
<h1>${model}</h1>
<button onclick=${msg.sub} disabled=${model <= 0}>-</button>
</div>`
})
from hyperapp.
It is decoupled because we provide defaults that can be overridden. The render function is curried before the view state. So the default is
require('h-app')(someModel)
// this starts a loop where the dom triggers re-rendering itself
// after the model changes
But the files are factored in such a way that you can do
var App = require('h-app/app')
var app = App(mySpecialRenderer)
app(myModel)
function mySpecialRenderer (tree) {
// ...
// tree is the return value from myModel.view
}
This necessitates an observable interface for the app state (via observ-struct
in my lib), so the renderer can subscribe to changes, whereas in hyperapp
the render function is baked in.
In the same spirit, you can do require('h-app/model)
, which is a function that returns a writable and an observable interface (a stream, basically) β writable via model.msg
, and observable via model.state
. So in relation to tests, this means we can do
var model = require('h-app/model')(MyModel)
Object.keys(model.msg).forEach(function (k) {
model.msg[k](mockInput[k])
})
model.state(function onChange (state) {
assert(/*...*/)
})
The next experiment I'm doing is factoring everything as a pull-stream, since everything is basically a stream anyway :)
from hyperapp.
What you want to decouple the render
function?
If that's so, then I can understand where you're coming from?
I totally understand the value of modules, decoupling, etc., but I've been the victim of too much decoupling, too much options, too much "build your own framework" kind of thing too.
I think this is worth exploring, so please share your findings back here. π
from hyperapp.
Yes, basically. The end goal is being able to write tests, the hypothesis is that we can expose the app state without using the Dom.
I have to go bicycle in the rain to the coop before it closes, but will almost certainly revisit these thoughts. Would be interested in hearing other people experiences pain points, and goals with browser applications.
from hyperapp.
@nichoth The end goal is being able to write tests
This implies you can't write tests now, which is not correct.
I'm also considering separating the render function in order support stuff like Electron, kinda like it went with Snabbdom and I think I can split things up and still stay under 1kb, since we're using rollup.
from hyperapp.
@jbucaran what would your application tests look like in hyperapp?
from hyperapp.
Would probably use jest like we are with HyperApp.
I'm juggling a lot of things at once, so I don't have a ready repo to share with you. Perhaps you could contribute w/ one?
from hyperapp.
yes It's one of my main goals at the moment :) . Where I'm at is that writing tests is 100% possible, but often too laborious to be worthwhile/feasible, and also not obvious as to what/how to test. Part of this varies depending on what kind of experiences we are coming from with applications and teams of developers.
I do have some beef with frameworks like jest, in that it seems too complicated, and I don't want to be dependent on something that needs a large corporation maintaining it because it is so vast. Ideally I would like to not use any framework that takes more than a weekend to read and understand.
from hyperapp.
I was unsure about jest at first, for pretty much the same reasons, but after being introduced to it by @maraisr, the more I use it, the more enjoyable I find it. I also wanted to try something new and the tooling is minimal.
In the future, when we make render document agnostic, π€ I may switch back to tape.
But I have to admit I'm pretty happy with jest so far.
from hyperapp.
Hi @nichoth! How's h-app coming along? π
I think we can close here, since this is not really an issue with hyperapp.
from hyperapp.
Related Issues (20)
- A way to insert raw Html HOT 1
- TypeError: can't access property 0, newSubs is null, when setting the state to undefined. HOT 4
- Issue with null-vnodes HOT 1
- prevent rerender node HOT 2
- The dispatch initializer ends in an endless loop on init when dispatching any action HOT 7
- Injected classes gets removed when using object/array to define class props HOT 1
- hyperapp version HOT 3
- Memo Data Gotcha HOT 5
- Confusing doc for actions -> wrapped actions HOT 5
- Passing arguments to init HOT 4
- [Question] Headless mode is still possible? HOT 1
- Destroying a child app HOT 8
- @hyperapp/html: use a Proxy? HOT 9
- Actions returning other Actions HOT 5
- Compile template tag to hyperscript HOT 17
- A challenge to hyperapp community HOT 1
- Has 2.0 been dropped from development? HOT 3
- oldSub[2] is not a function HOT 3
- Cannot read properties of null (reading 'length') HOT 5
- Unlikely Use Case bug in HTML and SVG Packages HOT 9
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 hyperapp.