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 🙏

© 2024 – Pkg Stats / Ryan Hefner

nativescript-behavior

v0.1.0

Published

Behavioral components for NativeScript Views

Downloads

4

Readme

Behavioral components for NativeScript Views

Build Status dependency status devDependency Status npm version

Package implements Strategy pattern to assign behavioral algorithms to NativeScript Views

Goal

The main goal of a project is to separate development process by two stages: desing and coding.

Demo

This repository is a source for npm package nativescript-behavior and a demo NatiteScript application.

Demo App shows how to unlock the NativeScript clicker achievement with Behavior components and without Model-View-ViewModel.

Installation

$ npm install --save joos-inheritance
$ npm install --save nativescript-behavior

Initialize module

To initialize the module you must require() it in your app/app.js:

require("nativescript-behavior");

Create behavioral algorithm

Algorithm is a ConcreteStrategy in terms of Strategy pattern. It must be a "subclass" of main Behavior "class". So, instance of ConcreteBehavior must be instance of main Behavior class.

Concrete behavior code must be in it's own file, it must be available for require() and module must export algorithm in exports.Behavior property.

var JooS = require("joos-inheritance");
var Behavior = require("nativescript-behavior").Behavior;

/**
 * @class ConcreteBehavior
 * @extends Behavior
 */
var ConcreteBehavior = JooS.Reflect(
    Behavior,
    /** @lends ConcreteBehavior.prototype */
    {
        onTap: function() {
            console.log(this.someProperty);
        },
        __constructor: function(contextView) {
            this.__constructor.__parent(contextView);
            this.someProperty = "someValue";
            this.nsObject.addEventListener("tap", this.onTap, this);
        },
        __destructor: function() {
            this.nsObject.removeEventListener("tap", this.onTap, this);
            this.__destructor.__parent();
        }
    }
);

exports.Behavior = ConcreteBehavior;

or

var Behavior = require("nativescript-behavior").Behavior;

var ConcreteBehavior = (function (_super) {
    __extends(ConcreteBehavior, _super);
    function ConcreteBehavior() {
        _super.apply(this, arguments);
        this.someProperty = "someValue";
        this.nsObject.addEventListener("tap", this.onTap, this);
    }

    ConcreteBehavior.prototype.onTap = function() {
        console.log(this.someProperty);
    };

    ConcreteBehavior.prototype.__destructor = function() {
        this.nsObject.removeEventListener("tap", this.onTap, this);
        _super.prototype.__destructor.apply(this, arguments);
    };

    return ConcreteBehavior;
})(Behavior);

exports.Behavior = ConcreteBehavior;

Put this code in ~/components/concreteBehavior.js for example

Create new CSS class for a view-with-behavior

Use a custom joos-behavior style property. It was implemented in this package to assign behaviors to views.

Page {
  joos-behavior: "nativescript-behavior/lib/page"
}

.concrete-behavior {
  joos-behavior: "~/components/concreteBehavior";
}

Put this code in your /app/app.css file

Also, you can assign behavior via concreteView.style.joosBehavior = "~/components/concreteBehavior.js" or concreteView.joosBehavior = "~/components/concreteBehavior.js"

Assign class to a view

<Page xmlns="http://schemas.nativescript.org/tns.xsd">
  <StackLayout>
    <Button class="concrete-behavior" text="Tap me!" />
  </StackLayout>
</Page>

Behavior will be attached immediately after setting joosBehavior style property and detached after setting this property to undefined

Also, behavior will be detached after Layout.removeChild(contextView); and attached back after Layout.addChild(contextView);

Tap the button

That's it =)

Features

  • Behaviors have parents and can interact with its siblings with this.parent.notify(eventData) method.
  • Behaviors can add/remove/toggle className of it's nsObject and set/remove attributes value