Code Monkey home page Code Monkey logo

sensorreader's Introduction

SensorReader

Sensor reader is a companion app to Remote Sensor Monitor, which itself is a companion to HWInfo.

SensorReader pulls measurements from Remote Sensor Monitor. It then displays them as a list, allowing you to favorite individual items. Disclaimer: I definitely have no design skills. ๐Ÿ™ˆ

dashboard

list

The why

While playing games on my PC, I want to track various stats, like temperature and CPU usage. I decided to write my own iOS client since there were none available for HWInfo. As it evolved, the project turned into a playground to study app architecture. It then split into two separate projects, SensorReader and ComposableSensorReader.

This is the SensorReader. To see ComposableSensorReader, click here.

Composition

I decided to see what Composition Root is all about. The Composition Root glues individual components together, allowing for greater separation of concerns. It allows the components to focus on doing one thing only, but with increased flexibility. Individual components specify their outward facing dependencies, and the Composition Root binds them. With this approach, the boundaries between components are clear and flexibility increases.

Of course I did not follow this to a T. There are still some places, where dependencies could be eliminated further and structure could be improved.

Structure

Let's take a look at app. We begin at the main app file, which calls upon the Composition Root object, to build the view hierarchy. Composition Root is where all the components are created and glued together. It gives us a dedicated space where we connect components with their dependencies. From here we can see a few objects and their dependencies instantiated. Objects like UseCases, Stores and a ViewModel for the settings. Right now, the settings only care about the URL of the server, but we need the ViewModel to do something else also. It shows the settings UI whenever the app is not configured, i.e. there is no server URL in the storage. Upon setting the URL, the ViewModel calls a function, which creates a new Reader objects and assigns it to the UseCase. This function lives in the Composition Root, so SettingsViewModel has no knowledge of the Reader object. ReadingsUseCase counts the number of it's subscribers. If it rises above 0, it will start a timer and fetch readings from the server at a specified time interval. Subscribers such as ReadingsViewModel or DashboardViewModel then attach to its publisher to receive updates. The UseCase only cares about the readings provider (a specific protocol), but does not hold a reference to any ViewModel. ReadingsView model has a task of mapping the readings into a list while also exposing an interface to set a particular reading as a favorite. DashboardViewModel gathers favorite readings in a list. Their respective views attach to their publishers and display the results.

Below is a rough outline of the architecture.

Architecture

sensorreader's People

Contributors

tadelv avatar

Watchers

 avatar Erik Drobne 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.