Giter Site home page Giter Site logo

zoe's Introduction

Zoe

2018-06-07

A minimal js utility to work with ajax related events. It's designed to work with ecp requests.

request

In the following example, the following uri is called:

  • /service/Ekom/ecp/api.php?action=back.morphic

The data array is passed to the script using HTTP POST. The response is formatted according to the ecp protocol.

zoe.inst().request("Ekom:back.morphic", data, function (response) {
    // now do something with the successful response...
});

on, trigger

We can define events using the on method, and trigger them later using the trigger method.

var api = zoe.inst();
api
    .on("myEvent", function () {
        alert("fire");
    })
    .trigger("myEvent");

We can also pass an array of event names:

var api = zoe.inst();


api.on(["myEvent", "anotherEvent"], function (eventName) {
    alert("fire ");
});


api.trigger("anotherEvent"); // alert fire
api.trigger("myEvent"); // alert fire
api.trigger("dumm"); // rien ne se passera ici
Pass arguments

We can also pass arguments

var api = zoe.inst();


api.on("myEvent", function (name, age) {
    alert("Je m'appelle " + name + " et j'ai " + age + ' ans');
});
api.trigger("myEvent", "Jordi", 4);

off

We can programmatically remove an event defined with the on method.

var api = zoe.inst();


api.on(["myEvent", "anotherEvent"], function (letter) {
    alert("fire " + letter);
});


api.off("myEvent");

api.trigger("anotherEvent", "a"); // alert a
api.trigger("myEvent", "b"); // nothing will happen here
api.trigger("dumm", "c"); // nothing will happen here

once

To remove an event after its first execution.

var api = zoe.inst();


api.on("myEvent", function () {
    alert("fire");
});
api.trigger("myEvent"); // fire
api.trigger("myEvent"); // fire


api.once("myEvent2", function () {
    alert("fire2");
});
api.trigger("myEvent2"); // fire2
api.trigger("myEvent2"); // rien ici

debounce

Reduce the number of callback calls to 1 within a given (very short) period of time.

// without debounce, the callback is triggered every time the keyboard is touched
jSearch.on('keyup.gui', function () {
    currentSearch = jSearch.val();
    refresh();
});


// with debounce the callback is triggered with a minimal delay of 250ms in-between every call (calls registered during this period are just dropped)
jSearch.on('keyup.gui', zoe.inst().utils.debounce(function () {
    currentSearch = jSearch.val();
    refresh();
}, 250));

History Log

  • 1.0.1 -- 2018-06-07

    • fix instance var=null error
  • 1.0.0 -- 2018-06-07

    • initial commit

zoe's People

Contributors

lingtalfi 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.