Socket
Socket
Sign inDemoInstall

@pelagiccreatures/sargasso

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pelagiccreatures/sargasso - npm Package Compare versions

Comparing version 0.7.3 to 0.8.0

dist/sargasso.iife.js

14

example/app.js

@@ -6,3 +6,3 @@ /*

import {
Sargasso, registerSargassoClass, bootSargasso
Sargasso, utils
}

@@ -14,3 +14,3 @@ from '../index.js' // or more likely from '@pelagiccreatures/sargasso'

}
from './lib/Noisy.js'
from '../lib/Noisy.js'

@@ -55,3 +55,3 @@ class myClass extends Sargasso {

registerSargassoClass('myClass', myClass)
utils.registerSargassoClass('myClass', myClass)

@@ -97,5 +97,5 @@ class MyButtonClass extends Sargasso {

registerSargassoClass('MyButtonClass', MyButtonClass)
utils.registerSargassoClass('MyButtonClass', MyButtonClass)
const loadPageHandler = bootSargasso({
utils.bootSargasso({
hijax: {

@@ -112,5 +112,1 @@ onError: (level, message) => {

})
export {
loadPageHandler
}
const doIt = () => {
alert('I\'m HIJAX injected.js. I contain js that is only used on this page.')
alert('I\'m HIJAX a injected script! I contain js that is only used on this page.')
}

@@ -4,0 +4,0 @@ export {

@@ -18,22 +18,2 @@ /*

import {
SargassoSupervisor
}
from './lib/SargassoSupervisor.js'
import {
Breakpoints, materialBreakpoints
}
from './lib/Breakpoints.js'
import {
HijaxLoader
}
from './lib/HijaxLoader.js'
import {
startServices
}
from './lib/Services.js'
import {
elementTools

@@ -43,36 +23,16 @@ }

let loadPage
const bootSargasso = (options = {}) => {
startServices(options)
const supervisor = new SargassoSupervisor(document.body, options)
supervisor.start(options)
if (options.breakpoints) {
const breakpoints = new Breakpoints(document.body, options.breakpoints)
breakpoints.start()
}
if (options.hijax) {
const hijax = new HijaxLoader(document.body, options.hijax)
hijax.start()
loadPage = hijax.setPage.bind(hijax)
} else {
loadPage = (url) => {
document.location.href = url
}
}
return loadPage
import {
loadPageHandler, bootSargasso
}
from './lib/boot.js'
// don't really like this but the only way I can find that allows a common scope
// for es6 and cjs bundles... TODO: revisit this
if (window) {
window.Sargasso = Sargasso
window.registerSargassoClass = registerSargassoClass
window.bootSargasso = bootSargasso
window.elementTools = elementTools
const utils = {
registerSargassoClass: registerSargassoClass,
bootSargasso: bootSargasso,
elementTools: elementTools,
loadPageHandler: loadPageHandler
}
export {
Sargasso, registerSargassoClass, bootSargasso, elementTools
Sargasso, utils
}
{
"name": "@pelagiccreatures/sargasso",
"version": "0.7.3",
"version": "0.8.0",
"description": "Simple, Fast, Reactive, supervised Javascript controllers for html elements.",

@@ -19,5 +19,5 @@ "keywords": [

"test": "echo \"Error: no test specified\" && exit 1",
"build": "npx webpack; rollup -c rollup.config.js",
"build": "rollup -c rollup.config.js",
"build-example": "rollup -c rollup.config.app.js",
"package-lodash": "lodash modularize exports=es include=camelCase,debounce;rm -r lib/lodash-modularize;mv modularize lib/lodash-modularize"
"build-cjs": "npx webpack"
},

@@ -24,0 +24,0 @@ "author": "Michael Rhodes",

@@ -28,4 +28,4 @@ # @PelagicCreatures/Sargasso

* Sargasso - the sargasso super class
* registerSargassoClass - function to register your sub classes
* bootSargasso - start sargasso services and HIHAX
* utils.registerSargassoClass - function to register your sub classes
* utils.bootSargasso - start sargasso services and HIHAX

@@ -35,3 +35,3 @@ [Most browsers](https://caniuse.com/#search=modules) are aware of ES6 and modules these days but but you can use the module/nomodule scheme to fall back to the common js bundle if needed.

```
<script type="module" src="https://cdn.jsdelivr.net/npm/@pelagiccreatures/sargasso/dist/sargasso.es.js"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/@pelagiccreatures/sargasso/dist/sargasso.iife.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@pelagiccreatures/sargasso/dist/sargasso.cjs.js" nomodule defer></script>

@@ -43,9 +43,14 @@ <script defer>

In production you probably want to host the bundles yourself instead of using the CDN and probably even make your own bundles including your subclasses using webpack or rollup or something. See rollup section below.
In production you probably won't use the prepackaged bundles but should build own bundles including your subclasses using rollup or something. See rollup section below. In this example we use the bundles for expediency. The prepackaged bundles expose the exports from the module as globals scoped under `PelagicCreatures`
For the '... your code here ...' part, it's the same in both cases. You need to at least start up the services.
```javascript
PelagicCreatures.Sargasso - the superclass for all Sargasso classes
PelagicCreatures.utils.registerSargassoClass - tell sargasso about your subclass
PelagicCreatures.utils.bootSargasso - start it up
PelagicCreatures.utils.elementTools - some utilities
PelagicCreatures.utils.loadPageHandler - the bottle neck for loading a page
```
```
<script>
<script defer>
let options = {

@@ -58,7 +63,7 @@ hijax: {

// boot supervisors and HIJAX loader
window.loadPageHandler = bootSargasso(options)
PelagicCreatures.utils.bootSargasso(options)
// define a custom class and register the classname.
class MyClass extends Sargasso {} // This won't do very much...
registerSargassoClass('MyClass',MyClass)
class MyClass extends PelagicCreatures.Sargasso {} // This won't do very much...
PelagicCreatures.utils.registerSargassoClass('MyClass',MyClass)

@@ -68,2 +73,9 @@ </script>

**In pure ES6** you don't need the 'PelagicCreatures.' bit, instead you would use import directly from the module.
```javascript
import {Sargasso, utils} from '@PelagicCreatures/sargasso'
utils.bootSargasso(options)
```
### Adding Your Sargasso class to an HTML element

@@ -295,21 +307,23 @@

export default {
input: './example/app.js', // load the app root
output: [{
format: 'es',
file: './example/app-bundle.es.js' // output the bundle
}],
input: './example/app.js',
output: [{
format: 'iife',
name: 'App',
file: './example/app-bundle.iife.js',
sourcemap: true
}],
plugins: [
json(),
nodeResolve({
preferBuiltins: false
}),
commonjs({
namedExports: {}
})
]
plugins: [
json(),
nodeResolve({
preferBuiltins: false
}),
commonjs({
namedExports: {}
})
]
}
```
Run `rollup -c rollup.config.app.js` and you have an ES6 bundle which includes all your dependancies
Run `rollup -c rollup.config.app.js` and you have an ES6 bundle which includes all your dependancies and code.

@@ -8,4 +8,6 @@ import commonjs from '@rollup/plugin-commonjs'

output: [{
format: 'es',
file: './example/app-bundle.es.js'
format: 'iife',
name: 'App',
file: './example/app-bundle.iife.js',
sourcemap: true
}],

@@ -12,0 +14,0 @@

@@ -8,4 +8,5 @@ import commonjs from '@rollup/plugin-commonjs'

output: [{
format: 'es',
file: './dist/sargasso.es.js',
format: 'iife',
name: 'PelagicCreatures.Sargasso',
file: './dist/sargasso.iife.js',
sourcemap: true

@@ -12,0 +13,0 @@ }],

const webpack = require('webpack')
const entry = {
main: './index.js'
main: './index.globals.js'
}

@@ -5,0 +5,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc