Introduction

Sqimitive.js – A Universal Primitive

Sqimitive.js is a minimalistic paradigm-agnostic building block for applications written in JavaScript (not necessary in-browser or DOM-related). It provides core infrastructure without much domain-specific logic that you can quickly develop thanks to its flexible API.

Sqimitive.js is under 20K (minified), sports documentation that is over 200 pages long (printed A4), needs no transpilers (plain pre-ES6 JavaScript, IE 11+) and depends only on a compatible utility library (NoDash no@ +16K, Underscore.js >=1.9.0 un: or LoDash) and, optionally, on jQuery jq: or Zepto (for Sqimitive\jQuery).

And it’s in public domain (http://unlicense.org).

from jqex

Example
var Task = Sqimitive.jQuery.extend({
  el: {tag: 'li'},

  _opt: {
    // Keep el appended to the parent's el.
    attachPath: '.',
    // Define the default attributes of Task:
    caption: '',
    done: false,
  },

  events: {
    // Update the visual presentation whenever any _opt changes:
    change: 'render',

    render: function () {
      this.el.text(this.get('caption'))
        .toggleClass('done', this.get('done'))
    },
  },

  elEvents: {
    // Listen for double clicks on this.el to change the done state:
    dblclick: function () {
      this.set('done', !this.get('done'))
    },
  },
})

// Create a parent container for our to-do items (Task's) which
// is placed into the DOM at $('#tasks'):
var list = new Sqimitive.jQuery({el: '#tasks'})

// Create a new item, add it to list's _children:
list.nest( new Task({caption: 'Ready steady go!'}) )
// ...append to list's el and render for the first time:
  .attach().render()

// Double click on Task's element in the window to change its
// className.

Resources

npm npm install sqimitive

If you spot a typo – select the fragment and press Ctrl+Enter. Help us keep this memo free of vexatious mistakes! Powered by https://github.com/ProgerXP/Orphus.

Basic code conventions

Customizing dependenciesdeps

Sqimitive can be included using several methods as implemented by umh.js. Each method has its own way of overriding dependencies (which default to NoDash no@ and jQuery jq:). Alternatively, you can change the deps variable in the source code but you’ll have to redo it on upgrade.

CommonJS/Node.js

In npm 8.3+, put this into your project’s package.json before doing npm install sqimitive (https://github.com/npm/cli/issues/4909):

"overrides": {
  "sqimitive": {
    "nodash": "npm:underscore",
    "jquery": "npm:zepto"
  }
}

AMD/Require.js

Use map and/or path options (https://requirejs.org/docs/api.html#config):

requirejs.config({
  map: {
    'sqimitive/main': {
      'nodash/main': 'lodash'
    },
    'sqimitive/jquery': {
      jquery: 'zepto'
    }
  },
  paths: {
    nodash: 'https://cdn.jsdelivr.net/npm/underscore@latest/underscore-umd-min.js'
  }
})

Plain <script>

Dependencies land in global window so simply fetch the needed script before including Sqimitive:

<script src="https://cdn.jsdelivr.net/npm/underscore@latest/underscore-umd-min.js"></script>
<script src="https://raw.githubusercontent.com/ProgerXP/Sqimitive/master/sqimitive.min.js"></script>

Defined in: HELP.chem, lines 81-172 (92 lines)