npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@oc-shopaholic/oc-request

v0.1.1

Published

oc-Request is vanilla js based replacement for standard OctoberCMS API. No dependencies. Based on native XMLHttpRequest.

Downloads

2

Readme

oc-Request

oc-Request is vanilla js based replacement for standard OctoberCMS API. No dependencies. Based on native XMLHttpRequest.

Build Status GitHub release npm (scoped)

Contents

Introduction

In modern frontend development, the use of jQuery is less and less encouraged and there are a number of reasons for this. Here are a few of them:

  1. Most of the jQuery functionality is easy to write on pure JS.
  2. jQuery greatly increases the size of the bundle, with most of the functionality is not used.
  3. jQuery encourages writing bad and unreliable code.

On most of my recent projects, I had to add jquery to the bundle just because of the request() function, so I decided that it was time to remove this vestige. I tried to keep the structure of request creation and response processing as similar as possible to current api. The only thing that has not been implemented is the part of the api that is based on 'data-' attributes. I find this functionality unnecessary and vulnerable due to the use of the eval() method.

Installation

NPM

npm install oc-request --save

Usage exmaple:

import request from 'oc-request';

// Send some information
request.sendData('ProductList::onAjaxRequest', {
    data: {
      сategory_id: id,
    },
    update: { 'product/slider/slider-ajax': '.slider-ajax-wrapper' },
    success: () => {
      doSomething();
    },
    complete: () => {
      doSomethingAfterSuccess();
    },
    loading: '.preloader-selector',
});

// Send form
const formNode = document.querySelector('.my-form');

request.sendForm(form, 'MakeReview::onCreate', {
   success: (res) => {
      completeHandler(res);
   },
});

Methods

There are two main methods for request object:

  1. sendData(handler, options);
  2. sendForm(form, handler, options).

The set of options is standard for both and very similar to standard OctoberCMS api

| Options | Default | Description |--- |--- |--- | |data|null|an optional object specifying data to be sent to the server along with the form data: {var: 'value'}. |update|null|an object, specifies a list partials and page elements (as CSS selectors) to update: {'partial': '#select'}. If the selector string is prepended with the @ symbol, the content received from the server will be appended to the element at begin or if string contains '^' symbol - at the end, instead of replacing the existing content. |flash|false|when true, instructs the server to clear and send any flash messages with the response. |files|false|when true, the request will accept file uploads, this requires FormData interface support by the browser. |loading|null|an optional string or object to be displayed when a request runs. The string should be a CSS selector for an element, the object should support the show() and hide() functions to manage the visibility. |redirect|true|string specifying an URL to redirect the browser to after the successful request. |success|null|Unlike the standard api, this is the primary method that runs when the query succeeds and runs AFTER the update () function. As a parameter, it takes ONE parameter - an object with a response from the server. |error|null|the callback function is executed in case of an error. Accepts error text as a parameter |complete|null|Executed AFTER success or error methods

Tips for easy migration

  1. For event delegation there is very useful library from github developers.
  2. You may to use axios or fetch for request to custom request to server.
  3. This package is designed for the latest browsers. For better compatibility don't forget to add it for Babel processing.

Get involved

If you're interested in the improvement of this project you can help in the following ways:

  • bug reporting and new feature requesting by creating issues on plugin GitHub page;
  • contribution to a project following these instructions.

Let us know if you have any other questions, ideas or suggestions! Just drop a line at [email protected].

License

© 2019, LOVATA Group, LLC under GNU GPL v3.

Developed by Uladzimir Ambrazhei.