Giter Site home page Giter Site logo

ranndev / angularjs-store Goto Github PK

View Code? Open in Web Editor NEW
10.0 3.0 3.0 1.11 MB

A tool to easily manage state in your AngularJS Application.

Home Page: https://angularjs-store.gitbook.io

License: MIT License

JavaScript 33.76% TypeScript 66.24%
angularjs angular1 state-management state-manager store angularjs-store

angularjs-store's Introduction

AngularJS Store - NgStore

AngularJS Store with AngularJS

AngularJS Store will guide you to create a one-way data flow in your application (Single Source of Truth). Manage your AngularJS application's state into a very predictable way.

Build Status codecov Greenkeeper badge

Installation

NPM

npm install --save @ranndev/angularjs-store

Yarn

yarn add @ranndev/angularjs-store

CDN

<!-- For development -->
<script src="https://cdn.jsdelivr.net/npm/@ranndev/[email protected]/dist/umd/angularjs-store.js"></script>

<!-- For production -->
<script src="https://cdn.jsdelivr.net/npm/@ranndev/[email protected]/dist/umd/angularjs-store.min.js"></script>

Quick Start

This tutorial will quickly get you started for the basics of AngularJS Store. For more advanced tutorials, check out the Tutorials with Javascript or Tutorials with Typescript from the official documentation.

Creating a store

First, you need to import the NgStore class from angularjs-store or if you are using CDN, NgStore class is globally available.

const initialState = { count: 0 };
const counterStore = new NgStore(initialState);

Making the store injectable

Wrapping the store by AngularJS service to make it injectable.

const app = angular.module('app', []);

app.service('counterStore', function counterStore() {
  const initialState = { count: 0 };
  const counterStore = new NgStore(initialState);

  return counterStore;
});

Getting the current state

Using the copy method to get a copy of state.

const app = angular.module('app', []);

app.controller('YourController', function YourController($scope, counterStore) {
  const counterState = counterStore.copy(); // { count: 0 }
  $scope.count = counterState.count; // 0
});

Updating the state

Using the dispatch for updating the state.

const app = angular.module('app', []);

app.controller('YourController', function YourController(counterStore) {
  // counterStore.copy() = { count: 0 }

  counterStore.dispatch('INCREMENT_COUNT', (currentState) => {
    return { count: currentState.count + 1 };
  });

  // counterStore.copy() = { count: 1 }

  counterStore.dispatch('DECREMENT_COUNT', (currentState) => {
    return { count: currentState.count - 1 };
  });

  // counterStore.copy() = { count: 0 }
});

Listening on state changes

Using the hook method to listen on dispatched actions.

const app = angular.module('app', []);

app.controller('YourController', function YourController($scope, counterStore) {
  counterStore.hook('INCREMENT_COUNT', (counterState) => {
    $scope.count = counterState.count;
  });

  counterStore.hook('DECREMENT_COUNT', (counterState) => {
    $scope.count = counterState.count;
  });
});

Stop listening on dispatched actions

const app = angular.module('app', []);

app.controller('YourController', function YourController($scope, counterStore) {
  const hookLink = counterStore.hook('INCREMENT_COUNT', (state) => {
    $scope.count = state.count;

    // Destory the HookLink when count reaches 10.
    // After the HookLink gets destroyed, the hook will no longer receive any dispatched actions.
    if ($scope.count === 10) {
      hookLink.destroy();
    }
  });
});

Documentation

Demo

Contributing

AngularJS Store is an open source project and we love to receive contributions from our community β€” you! There are many ways to contribute, from writing tutorials or blog posts, improving the documentation, submitting bug reports and feature requests. See the guidelines.

Collaborators

License

This project is licensed under the MIT License - see the LICENSE file for details

angularjs-store's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar greenkeeper[bot] avatar luz-domingo avatar rann00b avatar ranndev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

angularjs-store's Issues

Improve contributors and users guideline

  • Add CONTRIBUTING.md
  • Improve README.md
    • Add a quick start demo
    • Add collaborators section
  • Improve documentation
    • Create a tutorial for non typescript project
    • Add a comparison from broadcasting events (aborted)
    • Add a comparison for using AngularJS service (aborted)

An in-range update of webpack is breaking the build 🚨

The devDependency webpack was updated from 4.35.3 to 4.36.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

webpack is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

Release Notes for v4.36.0

Features

  • SourceMapDevToolPlugin append option now supports the default placeholders in addition to [url]
  • Arrays in resolve and parser options (Rule and Loader API) support backreferences with "..." when overriding options.
Commits

The new version differs by 42 commits.

  • 95d21bb 4.36.0
  • aa1216c Merge pull request #9422 from webpack/feature/dot-dot-dot-merge
  • b3ec775 improve merging of resolve and parsing options
  • 53a5ae2 Merge pull request #9419 from vankop/remove-valid-jsdoc-rule
  • ab75240 Merge pull request #9413 from webpack/dependabot/npm_and_yarn/ajv-6.10.2
  • 0bdabf4 Merge pull request #9418 from webpack/dependabot/npm_and_yarn/eslint-plugin-jsdoc-15.5.2
  • f207cdc remove valid jsdoc rule in favour of eslint-plugin-jsdoc
  • 31333a6 chore(deps-dev): bump eslint-plugin-jsdoc from 15.3.9 to 15.5.2
  • 036adf0 Merge pull request #9417 from webpack/dependabot/npm_and_yarn/eslint-plugin-jest-22.8.0
  • 37d4480 Merge pull request #9411 from webpack/dependabot/npm_and_yarn/simple-git-1.121.0
  • ce2a183 chore(deps-dev): bump eslint-plugin-jest from 22.7.2 to 22.8.0
  • 0beeb7e Merge pull request #9391 from vankop/create-hash-typescript
  • bf1a24a #9391 resolve super call discussion
  • bd7d95b #9391 resolve discussions, AbstractMethodError
  • 4190638 chore(deps): bump ajv from 6.10.1 to 6.10.2

There are 42 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of rollup is breaking the build 🚨

The devDependency rollup was updated from 1.27.6 to 1.27.7.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

rollup is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ build: There are 1 failures, 0 warnings, and 0 notices.

Release Notes for v1.27.7

2019-12-01

Bug Fixes

  • Fix a scenario where a reassignments to computed properties were not tracked (#3267)

Pull Requests

Commits

The new version differs by 4 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Automate package publishing

Add GitHub Actions's workflow that will automate the publishing of package to npm and GitHub Package Registry

An in-range update of @types/angular is breaking the build 🚨

The dependency @types/angular was updated from 1.6.54 to 1.6.55.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/angular is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Wrong in docs

https://angularjs-store.gitbook.io/docs/tutorials/update-the-state

Should it not be:

return { count: currentState.count + 1 };

and

return { count: currentState.count - 1 };

?


function YourController(counterStore: CounterStore) {
  counterStore.dispatch('INCREMENT_COUNT', (currentState) => {
    return { count: currentState + 1 };
  });

  counterStore.dispatch('DECREMENT_COUNT', (currentState) => {
    return { count: currentState - 1 };
  });
}

angular
  .module('App', [])
  .controller('YourController', YourController);```

An in-range update of rollup is breaking the build 🚨

The devDependency rollup was updated from 1.25.0 to 1.25.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

rollup is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • βœ… continuous-integration/travis-ci/push: The Travis CI build passed (Details).
  • ❌ continuous-integration/travis-ci/pr: The Travis CI build could not complete due to an error (Details).
  • ❌ codecov/project: CI failed. (Details).
  • ❌ codecov/patch: CI failed. (Details).
  • ❌ Travis CI - Pull Request: The build errored. This is a change from the previous build, which passed.
  • βœ… Travis CI - Branch: The build passed.

Commits

The new version differs by 7 commits.

  • b0d35e1 1.25.1
  • dc8e933 Update changelog
  • 24063a6 Handle conditional breaks in do-while loops with unconditional return (#3180)
  • 06fb16a Disable errors for duplicate emitted file names (#3175)
  • f99c7e4 Add original parser error to rollup error; Update tests (#3176)
  • 06047fc Fix switch case not being included correctly (#3178)
  • 73faf06 Update dependencies (#3179)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

GitHub Actions: Workflow (publish.yml) that publish the package doesn't include the dist folder from the tarball

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.