Nominally Patriotic Meathead
    Have ideas to improve npm?Join in the discussion! »

    anticore-serverless

    2.3.0 • Public • Published

    anticore-serverless

    An utility to easily write and test your anticore's middlewares, serverless

    Install

    `npm i anticore-serverless

    Live demo

    anticore-serverless demo

    Usage

    Listen a form submit

    Supposing you have a middleware to add some new messages to a messages list, like this:

    import { anticore } from 'anticore'
    import { one } from 'anticore/dom/query/one'
    import { append } from 'anticore/dom/tree/append'
     
    anticore.on('#messages li', (message, next) => {
      append(message, one('#messages'))
      next()
    })

    Register your templater like this:

    import serverless from 'anticore-serverless'
     
    serverless.on('main#message-sender form', (url, data, escape, session) => {
      return `<ol id="messages">
        <li>${escape(data.message)}</li>
      </ol>`
    })

    Listen an anchor click

    Supposing you have a middleware to load a new view, like this:

    import { anticore } from 'anticore'
    import { onClick } from 'anticore/dom/emitter/on/onClick'
    import { one } from 'anticore/dom/query/one'
    import { replace } from 'anticore/dom/tree/replace'
     
     
    anticore.on('section.hello', (section, next) => {
      const main = one('main')
     
      replace(section, main)
      onClick(one('.closer', section), () => replace(main, section))
     
      next()
    })

    Register your templater like this:

    import serverless from 'anticore-serverless'
     
    serverless.on('a[href="/say-hello"]', (url, escape, session) => {
      return `<section class="hello">
        <h1>Hello world</h1>
        <p>You asked the following url : ${escape(url)}</p>
        <button class="closer">Close</button>
      </section>`
    })

    API

    /**
    * Listens a form/anchor selector and sends the response to anticore, based
    * on the templater result
    @param {string} selector 
    @param {function} templater 
    @return {this} 
    */
    import serverless from 'anticore-serverless'
     
    serverless.on(selector, templater)

    Session

    session = session.set(name, value)
    value = session.get(name)
    session = session.reset()

    License

    MIT

    Install

    npm i anticore-serverless

    DownloadsWeekly Downloads

    2

    Version

    2.3.0

    License

    MIT

    Unpacked Size

    7.83 kB

    Total Files

    10

    Last publish

    Collaborators

    • avatar