Giter Site home page Giter Site logo

quickflux's Introduction

Message Dispatcher/Queue for Qt/QML

Build Status

QuickFlux is a Message Dispatcher / Message Queue solution for Qt/QML. It is also an implementation of Flux Application Architecture (from Facebook). By using this library, users may write their QML application in a Flux way. Their code could be more readable and reusable.

Features

  1. AppDispatcher
  2. A singleton Message Dispatcher / Message Queue per QML Engine.
  3. It guarantees the order of messages are arrived in sequence to listeners (First come first served)
  4. Write QML application in a Flux way.
  5. Helper function for C++ code to listen on QML event / obtain QML singleton instance
  6. Helper components for handling asynchronous sequential workflow.

Concept and Motivation

Generally speaking, you should avoid creating a big QML file. Break down into smaller piece of files is more readable and reusable. But it may not true due to event/signal propagation. Managing code dependence is very troublesome.

Writing QML in a Flux way is a solution for this problem. Using a global AppDispatcher for communication between components. It breaks the dependence and simplify your code by taking out unnecessary signal binding.

This project provides an implementation of dispatcher in QML for user to get started.

What is Flux and How to use in QML Application?

Please refer to this article for detail :

Action-Dispatcher Design Pattern for QML — Medium

or

A cartoon guide to Flux — Code Cartoons — Medium

An example program is available for demonstrate how to write QML application in a Flux way quickflux/examples/todo

Installation Instruction (with qpm)

For user who are already using qpm from qpm.io

  1. Run qpm install
$ qpm install com.github.benlau.quickflux
  1. Include vendor/vendor.pri in your .pro file

You may skip this step if you are already using qpm.

include(vendor/vendor.pri)
  1. Add import statement in your QML file
import QuickFlux 1.0

Installation Instruction (without qpm)

  1. Clone this repository or download release to a folder within your source tree.

  2. Add this line to your profile file(.pro):

    include(quickflux/quickflux.pri) # You should modify the path by yourself

  3. Add import statement in your QML file

import QuickFlux 1.0

Example Projects

There are few example programs available at examples folder:

Examples

Class Reference

QuickFlux 1.0 Class Reference

FAQ

Q1

Why use AppDispatcher instead of listening from AppActions directly?

Example:

import QtQuick 2.2
pragma Singleton

QtObject {

  signal openItem(string id);

  signal removeItem(string id);

}

ANS: Of course you could implement in this way. However, AppDispatcher offer two advantages over that approach:

  1. Avoid out-of-order message processing.

Signal emission in QML is , in fact, on last come, first served basis. If you emit another signal while in a callback, it will process the latest signal immediately. That means the sequence of message processing will be out-of-order. However, AppDispatcher will not dispatch a new message while in a callback. It will be placed in a queue until all of the listeners received the current message. So that the order of message is guaranteed to arrive in sequence.

  1. Setup dependence between stores.

Quoted from Why We Need a Dispatcher:

As an application grows, dependencies across different stores are a near certainty. 
Store A will inevitably need Store B to update itself first, so that Store A can know 
how to update itself. We need the dispatcher to be able to invoke the callback for Store B, 
and finish that callback, before moving forward with Store A. To declaratively assert this 
dependency, a store needs to be able to say to the dispatcher, "I need to wait for Store B 
to finish processing this action." The dispatcher provides this functionality through its 
waitFor() method."

AppListener supports “waitFor” property to setup dependencies on another AppListener. It won't process the emitted signal and wait until the other listener received the message. Therefore, you could control the order of message delivary.

Related Projects

  1. benlau/quickpromise - Promise library for QML
  2. benlau/quickcross - QML Cross Platform Utility Library
  3. benlau/qsyncable - Synchronize data between models

quickflux's People

Contributors

benlau avatar

Watchers

James Cloos avatar Laeeth Isharc avatar

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.