question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Introduce init and modules.

See original GitHub issue

We don’t have an elegant way to call any actions, subscribe to global events or kickstart ourselves when our app loads. We can call actions after we return from app() but packages like the router, a mouse / keyboard interop interface, etc., could be exposed as modules and for their initialization needs, we can introduce a new init function. 🎉

By the way, modules are not like mixins as they would be scoped to a state & action slice, that you can’t opt out from.

import { whopper } from "./whooper"
import { mouse } from "./mouse"

import state from "./myState"
import actions from "./myActions"
import view from "./myView"

app({
  init(state, actions) {
    // Subscribe to global events, start timers, fetch resources & more!
  },
  state,
  actions,
  view,
  modules: { whopper, mouse }
})

The modules whopper and mouse of this example can definitely expose their own init function. They would be called after the top-level init with a slice of the state and actions, e.g., state["whopper"] and actions["whopper"], just how it works with actions.

In @Zaceno’s words, what’s the difference between modules and mixins and how do we explain their overlap with HOAs?

This actually gets at the core of the problem I saw with mixins (and why I wanted them renamed from plugins as they once were called): they basically served two purposes: either to A) augment hyperapp’s features, or B) to modularize your app. Now, modules is only for (B), and we have HOA for (A).

/cc @lukejacksonn @zaceno @andyrj @Swizz

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:30 (23 by maintainers)

github_iconTop GitHub Comments

4reactions
zacenocommented, Oct 8, 2017

My previous comment was mostly against the idea of using actions inside init to set up initial state if that’s what you need (because it introduces two different types of actions). Of course init will need access to the final actions object (otherwise how to set up mousemove event handlers and similar).

So it was nothing against this proposal. I am for this proposal 😃

I’m especially a fan because it takes hyperapp one step further along the lines of hyperapp-partial. When this proposal makes it in I can decommission partial and just make two separate HOA (one to add an event bus, and one for prewired components in modules)

3reactions
zacenocommented, Feb 27, 2018

@augnustin I’d go with what @SkaterDad said, because it keeps state management logic out of the view.

In case you’re interested about modules and initialization with current versions of hyperapp, I’ve written a bit about it. Nothing official - just my approach, but in case you’re interested:

https://zaceno.github.io/hypercraft/post/modular-apps/ https://zaceno.github.io/hypercraft/post/initialization/ https://zaceno.github.io/hypercraft/post/cross-namespace-action-calling/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Modules, introduction - The Modern JavaScript Tutorial
A module exports some means of configuration, e.g. a configuration object. On the first import we initialize it, write to its properties. The ......
Read more >
Package Initialization - Real Python
In this video, you're going to learn about package initialization. When talking about package ... Python Modules and Packages: An Introduction
Read more >
Chapter 1. Introduction to cloud-init Red Hat Enterprise Linux 8
cloud-init is a software package that automates the initialization of cloud instances during system boot. You can configure cloud-init to perform a variety ......
Read more >
6. Modules — Python 3.11.1 documentation
A module can contain executable statements as well as function definitions. These statements are intended to initialize the module. They are executed only...
Read more >
Using Go Modules - The Go Programming Language
An introduction to the basic operations needed to get started with Go ... go mod init example.com/hello go: creating new go.mod: module ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found