Hyperapp: 鈿★笍 Ideas for useful mixins

Created on 3 Jul 2017  路  12Comments  路  Source: jorgebucaran/hyperapp

Presuming _mixin_ functionality remains as we know it today.. what are they most useful for? Can we think of any low level implementations like the Logger that would be useful in many projects?

Some inspiration:

  • InternalLinker - handles the routing of internal views
  • MouseTrap - maps mouse events to the app state
  • WindowScroller - maps window scroll position to the state
  • MediaPlayer - wraps native audio/video element state and actions
  • FirebaseStore - connects to realtime db and emits stream events

There are no _wrong_ answers here! Any responses that get many positive reactions will get added to the inspiration list above for others to make note.

馃摝 Bonus points for extra creative naming

Community Discussion

Most helpful comment

I'm basically using mixins for these things:

  1. share code across hyper app apps (we have one project on @attach-live that has 4-5 instances of HyperApp running in a single website, lol)
  2. scope code by category (Similar to what router does, but for stuff like WebRTC and iframe management/postMessage)
  3. generic logger functionality that I plug into every HyperApp project I have.

To reduce "spam" in my email inbox I unsubscribe from most threads. @mention me if you want to respond.

All 12 comments

@lukejacksonn Good question! Let's see what kind of response do you get.

By the way, mixins (formerly known as plugins) were introduced when we decided to decouple the previously built-in router from app.js into its own file.

Here a starter for hyperapp package shameless based on the @hyperapp/router : Swizz/hyperapp-package

I dont know the @jbucaran thoughts about it, but I think I will personally use this to quick start hyperapp package with ease :tada:
(Ill be glad to gift it to the org)

@Swizz That is cool, but please notice @lukejacksonn is trying to collect ideas for mixins.

Ideas for useful mixins

:)

Ow sorry, I thinked he was asking for Mixins (and alike) creation. I can remove my comment as you wish.

Inspired by the firebase-store-idea: something that lets you control and react to PouchDB replication
PouchDBInterface maybe? (I know, I'm not getting bonus points for that one)

@Swizz No need to do that. 馃槃

Another example are mixins that wrap views to provide something similar to what we were trying to achieve with components.

Here is a simple one:

const Component = mixin => (props, children) =>
  "view" in props ? mixin : mixin.view(props.state, props.actions, children)

@lukejacksonn Isn't MediaPlayer more like a component (prev. known as custom tags)?

@jbucaran: but if you want to keep the player controls in sync with the app (perhaps to implement a custom player-controls-bar) you'll need more than just the vtree. Youll need the state, events, and actions too. Seems like the perfect candidate for a mixin to me

@zaceno I see what you mean. 馃憤

What @zaceno said! This would work especially well with https://github.com/MatejMazur/hyperapp-mixin

I'm basically using mixins for these things:

  1. share code across hyper app apps (we have one project on @attach-live that has 4-5 instances of HyperApp running in a single website, lol)
  2. scope code by category (Similar to what router does, but for stuff like WebRTC and iframe management/postMessage)
  3. generic logger functionality that I plug into every HyperApp project I have.

To reduce "spam" in my email inbox I unsubscribe from most threads. @mention me if you want to respond.

Thanks for the feedback y'all.. closing this for now!

Was this page helpful?
0 / 5 - 0 ratings