Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hh rm mixins #245

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Hh rm mixins #245

wants to merge 5 commits into from

Conversation

hhaensel
Copy link
Member

@hhaensel hhaensel commented Nov 30, 2023

Currently we have no possibility of including vue mixins.

This PR uses the existing rendering methods for ReactiveModels and makes it possible of including named apps as mixins.
The idea is to make it easier to develop reusable Plugins.

A demo is given in the doc string of the new macro @mixins.

using Stipple, Stipple.ReactiveTools
using StippleUI

@app GreetMixin begin
  @in name = "John Doe"
end

@mounted GreetMixin = "console.log('Just mounted the App including the GreetMixin')"

@methods GreetMixin :greet => "function() { console.log('Hi ' + this.name + '!') }"

@mixins [GreetMixin]

@app begin
  @mixin GreetMixin
  @in s = "Hi"
  @in i = 10
end

ui() = btn("Say Hello", @click("greet"))

@page("/", ui())

up(open_browser = true)

@essenciary @PGimenez I made this a draft PR to discuss whether this implementation is sufficient or how we could develop this further.

  • Currently, I don't have a clear idea how to support pre- / postfixes that we support with the @mixin, we would need to define js_methods, etc with optional kwargs pre and post, I suppose.
  • currently, it is necessary to add the mixins at two places. We could modify the @mixin macro to call @mixins. This will currently not work properly without supporting post and prefixes, at least, if the mixins are used like @mixin hh::MyMixin because that calls @mixin with a prefix.
  • Currently the handlers are not ported

@hhaensel
Copy link
Member Author

Example use case:

You have a multipage app and an SSO load script.
Then you can define all fields and scripts to manage your SSO sign-on for your sign-on-app and simply include it in all pages.

@hhaensel
Copy link
Member Author

hhaensel commented Dec 1, 2023

Update: embedding handlers without prefixes is easy an already included now

@hhaensel
Copy link
Member Author

hhaensel commented Dec 1, 2023

Demo App

# Test of `@mixins` from branch hh-rm-mixins (https://github.com/GenieFramework/Stipple.jl/pull/245)

using Stipple, Stipple.ReactiveTools
using StippleUI

@app GreetMixin begin
  @in name = "John Doe"

  @onchange name begin
    println("'name' changed to $(name)!")
  end

end greet_handlers

@mounted GreetMixin = "console.log('Just mounted the App including the GreetMixin')"

@methods GreetMixin :greet => "function() { console.log('Hi ' + this.name + '!') }"

@mixins [GreetMixin]

@app begin
  @mixin GreetMixin
  @in s = "Hi"
  @in i = 10

  @onchange i begin
    println("'i' changed to $(i)!")
  end
end

ui() = row(cell(class = "st-module", [
  cell(class = "q-my-md q-pa-md bg-green-3", "Name: {{name}}")
  cell(class = "q-my-md q-pa-md bg-green-4", "i: {{i}}")
  
  btn("client mixin 'greet'", @click("greet"), color = "red-3", nocaps = true)
  btn(class = "q-ml-md", "backend mixin '@onchange name'", @click("name = 'John ' + (name.endsWith('Doe') ? 'Dough' : 'Doe')"), color = "red-3", nocaps = true)
]))

@page("/", ui)

up(open_browser = true)

@PGimenez PGimenez self-requested a review December 14, 2023 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant