Coder Social home page Coder Social logo

actions's Introduction

dojo-actions

Build Status codecov.io npm version

A command like library for Dojo 2 Applications.

NOTE At this stage, this is a functional prototype for a proposal that is under discussion. This is not yet intended for production use. Consider it pre-alpha and is intended to allow people to assess the API. Use at your own risk and the final API may or may not look anything like this

Features

Actions embody the concept of doing something that can be express behaviour without having to re-implement the behaviour in various locations of an application. In the concept of a Dojo 2 application, Widgets call Actions which mutate state in Stores which change the State of Widgets.

Creation

To create a new action, simply use the Action factory:

import createAction from 'dojo-actions/createAction';

const action = createAction({
    do() {
        /* do something */
    }
});

action
    .do()
    .then((result) => {
        /* do something with the result */
    });

You must specify a do() method when using the Action factory. The Action will wrap the .do() method, ensuring that no matter what the return, it will return a dojo-core/async/Task which is a Promise with the ability to cancel.

State

Each Action has a .state object which contains any sort of mutatable state. This is provided by the dojo-compose/mixin/createStateful mixin. When the .do() method is invoked, it is scoped so that this is the calling action, and therefore this.state can be used to read from the state.

Future

It is envisioned that some foundational "helper" actions will be added to this package to make it easy.

How do I use this package?

The easiest way to use this package is to install it via npm:

$ npm install dojo-actions

In addition, you can clone this repository and use the Grunt build scripts to manage the package.

Using under TypeScript or ES6 modules, you would generally want to just import the dojo-actions/createAction module:

import createAction from 'dojo-compose/createAction';

const action = createAction({
    do() { /* do something */ }
});

action.do();

How do I contribute?

We appreciate your interest! Please see the Dojo 2 Meta Repository for the Contributing Guidelines and Style Guide.

Testing

Test cases MUST be written using Intern using the Object test interface and Assert assertion interface.

90% branch coverage MUST be provided for all code submitted to this repository, as reported by istanbul’s combined coverage results for all supported platforms.

To test locally in node run:

grunt test

To test against browsers with a local selenium server run:

grunt test:local

To test against BrowserStack or Sauce Labs run:

grunt test:browserstack

or

grunt test:saucelabs

Licensing information

TODO: If third-party code was used to write this library, make a list of project names and licenses here

© 2004–2015 Dojo Foundation & contributors. New BSD license.

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.