Coder Social home page Coder Social logo

js-guardvar's Introduction

JS-GuardVar

Guard the function execution on a variable

Version

0.01

Synopsis

    var guard = new Guard(true); // get a initially openned guard.

    setInterval(guard.guard(function(){ console.log("Hi") }), 1000);

    // pause the guard, all the later fired events will be queued
    guard.pause();

    // pause the guard, all the later fired events will be discarded
    guard.stop();

    // open the guard, all the queued event will fire now;
    // and the later fired events will all fire immediately.
    guard.open();

Install

If you use GreenDefine or RequireJS you can load it as a module.

define([..., 'GuardVar', ...], function(..., GuardVar, ...){
    var gv = new GuardVar(true);
    ...
});

If you use this library stand alone.

<script type="text/javascript" src="GuardVar.js"></script>
<script type="text/javascript">
    var gv = new GuardVar(true);
    ...

    var TheGuardVar = GuardVar.noConflict();
    // The noConflict function will release window.GuardVar to its original value,
    // and return the GuardVar to you.
</script>

API Reference

  • gv = new GuardVar(init_open)

    Get a new GuardVar.

    If the init_open is true, the gv is initially opened; the gv is initially stopped otherwise.

  • guarded_function = gv.guard(function)

    Get a guarded_function.

    When the guarded_function is called, it will check the gv's state to decide whether or when to call the function with same arguments it received.

  • gv.pause()

    Pause the gv.

    All the later calls on the guarded_functions will be queued.

  • gv.stop()

    Stop the gv.

    All the later calls on the guarded_functions or queued calls will be discarded.

  • gv.open()

    Open the gv.

    All the queued calls will fire now. And all the later calls on the guarded_functions will fire immediate.

Lincense

Copyright 2012, Cindy Wang (CindyLinz)
Licensed under the MIT or GPL Version 2 licenses or GPL Version 3 licenses.

Date: 2012.10.26

js-guardvar's People

Contributors

cindylinz avatar

Watchers

 avatar James Cloos 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.