Giter Club home page Giter Club logo

Comments (4)

bcardarella avatar bcardarella commented on August 23, 2024

That's an interesting idea with the app:gps but wouldn't that mean that you want to match the value rather than ignore it?

As far as the form controls go, that API is not guaranteed at the moment. It got us to ElixirConf but we'll be extracting that out into its own library instead of being included in the standard swift ui client. We'll need more time to determine if the API is stable or not.

from liveview-client-swiftui.

clsource avatar clsource commented on August 23, 2024

Ok so here are some ideas for the event system.

The native app can trigger two different type of events.

  1. Events that require UX responses (trigger a message, update a table)
  2. Events that are just important to the server and will not trigger an update to the user ui.

Classes

classDiagram
class IHandleEvents {
        - status :: Integer.t
        - options :: Map.t
        - handle(params :: Map.t)
        - init(with: status :: Integer.t, options: options :: Map.t)
        - set(options: options :: Map.t)
}

A interface or protocol that defines the behaviour of an event handler.

classDiagram
class PushNotificationEventHandler~IHandleEvents~ { }

An example event handler that will focus on Push Notifications.
This is the Dispatcher of Server Events.

classDiagram
class EventHandlersLocator{
   - add(event :: Any~IHandleEvents~)
   - get(event :: Any~IHandleEvents~.class.t)
   - remove(event :: Any~IHandleEvents~.class.t)
    - handlers :: Map.t(key:  Any~IHandleEvents~.class.String.t, value: Any~IHandleEvents~)
}

This service will store a single intance of each event handler. These instances are created in AppDelegate.
So a Single Handler can be responsible for dispatching events. The handlers registry will store
the string representation of the class of each handler as its key.

classDiagram
class ServerEvent {
       - name :: String.t
       - params :: Map.t
       - init(name :: String.t, params :: Map.t)
       - send()
       - send(params :: Map.t)
}

The object that will send the information to the server and maybe send a message to
the NotificationCenter

UI Events

These events will need to be defined inside the LiveView template, because they will trigger a LiveView handle_event function.

Example

<app.event name="app:gps:realtime" opts={ [every: :seconds30] }>

In a normal LiveView this maybe a hidden input which will trigger on change event.

<input type="hidden" data-every="seconds30" phx-change="app:gps:realtime" value="">

It will configure the native app event. Enabling it and sending its options as Json.

{
 "name": "app:gps:realtime",
  "opts": {
      "every": "seconds30"
   }
}

In the LiveView component

def handle_event("app:gps:realtime", value, socket) do
  # server handling code
end

The value would be a json object containing the data.
If the data is an Image, Sound, File or another not JSON encodable,
it must be encoded as base64 string.

{
  "name" : "app:audio",
  "data" :  "bGlnaHQgdw=="
}

Server Events

These events will send a POST request to a specific endpoint in the server. So they will not be defined in the
template. Since they will not be related to LiveView. The configuration must be done inside the Native App.

from liveview-client-swiftui.

stevegraham avatar stevegraham commented on August 23, 2024

Why can't pushEvent on the coordinator be used if no user interaction is required?

from liveview-client-swiftui.

AZholtkevych avatar AZholtkevych commented on August 23, 2024

It is not planned. Rejecting. We have other way to do that: https://liveview-native.github.io/liveview-client-swiftui/documentation/liveviewnative/liveviewcoordinator/pushevent(type:event:value:target:)

from liveview-client-swiftui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.