npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

staballoy

v1.1.2

Published

Reactive Library for binding data to UI elements in Titanium Alloy

Downloads

9

Readme

Staballoy

State Manager & Reactive UI framework for Titanium Alloy with event handling

How does it work?

Staballoy maintains an object of data, stored in Ti.App.Properties, any alteration in this data (by setting the state) will cause the library to find any UI elements that need updating automatically.

Setup

So how do I install it? For Alloy projects go to the lib directory of your project (app/lib), then run the following command npm i staballoy for Webpack projects run the npm install in your app root.

Note: if your Alloy app doesn't have node_modules yet, run npm init first!

Getting/Setting data

Staballoy stores all data in a single Ti.App.Properties object, so anything you set will add to this dataset. Staballoy automatically deep-merges the data you set, so you do not have to worry about overwriting/losing data if you do not include the already set data.

Note: Setting an array will not merge the existing array in the same place, array's overwrite

Setting data

To set data in staballoy, all you need to do is call the set method and provide any data you want to add to the dataset

require('staballoy').set(object);

An automatic deep merge will be initiated on the data you set.

Resetting data

Instead of using set you can also use reset so you don't deep merge data, but override it instead. This will remove all data currently stored.

require('staballoy').reset(object);

Getting data

To get all the data currently set in the staballoy storage, call the get method

const data = require('staballoy').get();

The get method has an optional argument, if you provide this argument you can return a subset of the data. A deep search is performed to get this property, so you can provide a path to the property you want to fetch.

const data = require('staballoy').get('my.nested.property');

This will return Hello, World! when the data has been set as {my: { nested: { property: "Hello, World!"}}}.

Subscribe

Of course the most important feature is subscribing to any data you have set. To enable subscribing all you need to do is add the module="staballoy" tag to any UI element you want to have support for this.

<View module="staballoy" id="myView" />

To enable an entire controller at once, add this to the Alloy tag.

<Alloy module="staballoy">

Once this is set, dive into your tss and add subscriptions, using a path to the property you want to set it to, and the property you want to update. There are 2 methods of subscribing, simple or with a transform method.

Simple Subscribe

You want to set the color and text property of a <Label> based on a user profile:

<Label id="myLabel" module="staballoy" />

Then in the tss:

"#myLabel": {
    staballoy: {
        text: "user.name",
        color: "user.favoriteColor"
    }
}

Then setting that data in staballoy is simple:

require('staballoy').set({user: {name: "John Doe", color: "#6F2E25"}});

This will automatically change the color and text of the Label, on the fly, and anything you set is stored so you only need to do this once.

Subscribing with dataTransform

If you want to tranform the data prior to setting it, you can add the transform method to the subscription. We're taking the example above and altering it to support transformation.

First, in tss set transform to true this way:

"#myLabel": {
    staballoy: {
        text: {
            value: "user.name",
            transform: true
        },
        color: "user.favoriteColor"
    }
}

This will disable staballoy to automatically set the text value for you, but it will still automatically set the color. Instead it will trigger the tranform event on the UI element. So, time to subscribe to the UI element.

<Label id="myLabel" module="staballoy" onTransform="handleLabelTransform" />

And then in the controller you need to create your transform handler:

function handleLabelTransform(e) {
    e.source[e.key] = e.value;
}

As you can see, the event contains the source, the key of what needs changing, and the value. In our situation the source is the <Label>, the key is text and the value is John Doe. But now you can do anything you want with the value you wish, just don't forget to apply the property to the UI element as Staballoy won't do this automatically anymore.

For example you now could do this:

function handleLabelTransform(e) {
    e.source[e.key] = `Your name is: + ${e.value}`
}

Debug

Want to get more logging? Enable debug mode! Add this line to alloy.js and you should be good

require('staballoy').setDebug(true);

Any UI property that is not creation- or read-only is supported. Most UI elements are supported too

Missing features / bugs / questions?

For missing features and bugs, please submit a ticket, or even better submit a Pull Request.

If you have any questions, just contact me on TiSlack. My name there is @Wraldpyk.

Want to support my work? Send a donation my way via the Ko-Fi button on TiSlack.org. Any support is appreciated.

Changelog

  • 1.1.1 - (20210212) Arrays no longer merge, but they overwrite
  • 1.1.0 - (20210205) Added ability to add a dataTransform to subscription
  • 1.0.4 - (20210128) Fixed property search when property value was falsy
  • 1.0.1 - (20210127) Added garbage-collection and debug mode
  • 1.0.0 - (20210119) Complete rewrite of the module
  • 0.3.3 - (20180905) Fixed issue where creating empty controllers crashed the app
  • 0.3.0 - (20180711) Added 2-way binding and deep-binding.
  • 0.2.4 - (20171205) Add the ability to manual subscribe with a guid instead of a window.
  • 0.2.3 - (20171030) Ignoring the setVar function call if the new value is the same as the stored one
  • 0.2.2 - (20171024) Subscriptions of top most element weren't processed. Now they are!
  • 0.2.1 - (20171019) Added support for NavigationWindows & ListSections. Fixed elements with children not being able to subscribe
  • 0.2 - (20171012) Added direct subscribers from tss instead of controllers
  • 0.1 - (20170928) First release