0.0.53 • Published 3 years ago

@madebywink/shwing v0.0.53

Weekly downloads
1
License
ISC
Repository
github
Last release
3 years ago

Shwing JS

What is it?

A Shopify Storefront API toolkit for Frontend Devs on a time budget.

Powerful!

dev: Code Style

The coding preferences of this repo can be described as:

  • descriptive, helpful, and minimal
  • functional, i.e. currying etc.
  • classless
  • immutable
  • data-safe
  • clean, concise scopes
  • lazy, asynchronous, and (where appropriate) reactive

But most importantly, do the thing.

Setup:

Be sure to check for the latest version here: https://www.npmjs.com/package/@madebywink/shwing

CDN: (i.e. Webflow embed)

<script src="https://cdn.jsdelivr.net/npm/@madebywink/shwing@0.0.25/dist/index.min.js"></script>
const Product = shwing.ShopifyProduct(productOptions)
const Cart = shwing.ShopifyProduct(cartOptions)

NPM: (i.e. Svelte component)

npm install --save shwing
import {
    ShopifyProduct,
    ShopifyCart
} from '@madebywink/shwing'

const Product = ShopifyProduct(productOptions)
const Cart = ShopifyProduct(cartOptions)

Cart:

Basic usage:

const options = {
    GQL_ENDPOINT_URL: "https://shopify-store-name.myshopify.com/api/2020-07/graphql",
    STOREFRONT_ACCESS_TOKEN: "aabc1234d5e6f7g0etc",
    onInit: (cartDetails, lineItems, cartNote, customAttributes) => {
        // do stuff
    },
    onUpdateState: (cartDetails, lineItems, cartNote, customAttributes) => {
        renderLineItems(lineItems)
        replaceCartDetails(cartDetails)
    }
}

const Cart = ShopifyCart(options)

window.onload = async function() {
    await Cart.init()
}

function renderLineItems(lineItems) {
    // do stuff
}

function replaceCartDetails(cartDetails) {
    // do stuff
}

Product:

Basic usage:

const options = {
    GQL_ENDPOINT_URL: "", /* https://shopify-store-name.myshopify.com/api/2020-07/graphql */
    STOREFRONT_ACCESS_TOKEN: "", /* long string of numbers and letters */
    onInit: (defaultProduct, variants) => {
        hydrateProductPage(defaultProduct, variants)
        addFormHandlers()
    },
    handle: "your-product-slug"
}

const Product = ShopifyProduct(options)

window.onload = async function() {
    await Product.init()
}

function hydrateProductPage (defaultProduct, variants) {
    //do stuff
}

function addFormHandlers () {
    // do stuff
}

ShopifyProduct:

const cartOptions = {...}
const Cart = ShopifyCart(cartOptions)

The Cart requires an options object of the following shape:

const options = {
    GQL_ENDPOINT_URL: "", /* https://shopify-store-name.myshopify.com/api/2020-07/graphql */
    STOREFRONT_ACCESS_TOKEN: "", /* long string of numbers and letters */
    onInit: (cartDetails, lineItems, cartNote, customAttributes) => {
        // do stuff
    },
    onUpdateState: (cartDetails, lineItems, cartNote, customAttributes) => {
        // do stuff
    }
}

Cart will be a returned Object containing various methods, including an initialization function, Cart mutation functions, getters, and setters.

These methods are only safe to use AFTER initialization.

{
    init() => undefined,
    query: {  
        cartState(onThisUpdate: function) => undefined,
    },
    mutate: {  
        lineItemQuantity(variantId: "...", quantity: 1) => undefined,
        removeLineItem(variantId: "...") => undefined,
        cartNote() => undefined,
        cartCustomAttributes() => undefined,
    },
    get: {
        lineItems() => [...],
        cartDetails() => ({...}),
        cartNote() => "...",
        customAttributes() => [...],
        _checkoutId() => ""
    },
    set: {
        cartNote("..."),
        customAttributes([{key: "", value: ""}])
    }
}

ShopifyCart

const productOptions = {...}
const Product = ShopifyCart(productOptions)

The Product requires an options object of the following shape:

const options = {
    GQL_ENDPOINT_URL: "", /* https://shopify-store-name.myshopify.com/api/2020-07/graphql */
    STOREFRONT_ACCESS_TOKEN: "", /* long string of numbers and letters */
    onInit: (cartDetails, lineItems, cartNote, customAttributes) => {
        // do stuff
    },
    onUpdateState: (cartDetails, lineItems, cartNote, customAttributes) => {
        // do stuff
    }
}

Product will be a returned Object containing various methods, including an initialization function, an addToCart funciton, getters, and setters.

These methods are only safe to use AFTER initialization.

{
    init() => undefined,
    api: {
        addToCart(customAttributes: [{key: "", value: ""}]) => undefined
    },
    get: {
        selectedVariant() => ({...}),
        deliveryDate() => "...",
        defaultProduct() => ({...}),
        variants() => [...],
        _checkoutId() => "..."
    },
    set: {
        selectedVariant({...}),
        deliveryDate("...")
    }
}

Shwing!

Powerful!

0.0.44

3 years ago

0.0.45

3 years ago

0.0.46

3 years ago

0.0.47

3 years ago

0.0.51

3 years ago

0.0.52

3 years ago

0.0.53

3 years ago

0.0.50

3 years ago

0.0.48

3 years ago

0.0.49

3 years ago

0.0.41

3 years ago

0.0.42

3 years ago

0.0.43

3 years ago

0.0.40

3 years ago

0.0.39

3 years ago

0.0.37

3 years ago

0.0.38

3 years ago

0.0.30

3 years ago

0.0.31

3 years ago

0.0.32

3 years ago

0.0.33

3 years ago

0.0.34

3 years ago

0.0.35

3 years ago

0.0.36

3 years ago

0.0.29

3 years ago

0.0.26

4 years ago

0.0.27

4 years ago

0.0.28

4 years ago

0.0.21

4 years ago

0.0.22

4 years ago

0.0.23

4 years ago

0.0.24

4 years ago

0.0.25

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.14

4 years ago

0.0.15

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago