<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          ApplicationContext for Node.js

          聯(lián)合創(chuàng)作 · 2023-09-23 17:15

          介紹

          這是一個針對 Node.js 方面的ApplicationContext,作用于全局應用的Key-Value的Setter與Getter,并同時具有事件觸發(fā)響應,重點解決在開發(fā)Node.js應用時,缺少良好應用級別的全局變量控制或者配置。

          如何使用

          npm install applicationcontext --save

          API

          要求

          var AppContext = require('applicationcontext');

          Setter & Getter

          set([key,]value)

          • key {String}, Optional : 鍵,形式為 'a.b.c'

          • value {AnyType} : 如果沒有key參數,那么這里可以使用原型對象,但是千萬要注意的是原型對象中的key絕對不能是'a.b.c'這樣的結構,否則get會返回undefined

          AppContext.set("username","Jimmy Song");
           console.log(AppContext.get("username"));
           //Use Plain Object like this
           AppContext.set({
           session : { name : "user", expire : 3000 }, 
          // do not name key that look like 'a.b.c', it's error  "local.name" : "good" });
           console.log(AppContext.get("session.name"));
           // output : user console.log(AppContext.get("local.name"));
           // output : undefined

          get(key)

          • key {String} : e.g AppContext.get('username'); or AppContext.get('session.name')

          remove(key)

          • key {String} : e.g AppContext.remove('username'); or AppContext.remove('session.name')

          clear()

          • Remove All data

          Event

          on(key,listener)

          // 為某個鍵添加監(jiān)聽 AppContext.on('session.name',function(value,message){
           // 這里的value是key對應的值,而message是觸發(fā)事件時可選的消息
           console.log("the value is ",value); console.log("and extra message is ",message);
           });

          emit(key,message)

          // 觸發(fā)事件時,傳遞的如下的消息
           AppContext.set('session.name','Freeman');
           AppContext.emit('session.name','hi, there is extra information, just tell you the session.name value is changed');

          off(key [ , listener ] )

          // Remove the specified listener for 'session.name'
           AppContext.off('session.name',listener); 
          // Remove all listener for 'session.name'
           AppContext.off('session.name');
          瀏覽 14
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  天天操夜夜操xxxxxx | 国产偷窥盗摄7777777 | 最新热播日韩女优网站 | 国产精品成人小电影 | 草草视频免费观看 |