@erickmerchant/framework
Advanced tools
Comparing version 8.0.0 to 9.0.0
@@ -1,6 +0,3 @@ | ||
'use strict'; | ||
"use strict"; | ||
var catchLinks = require('catch-links'); | ||
var singlePage = require('single-page'); | ||
module.exports = function (_ref) { | ||
@@ -15,16 +12,7 @@ var target = _ref.target, | ||
var href = void 0; | ||
var state = store(); | ||
var rafCalled = false; | ||
var show = singlePage(function (newHref) { | ||
href = newHref; | ||
render(); | ||
}); | ||
catchLinks(target, show); | ||
return function (init) { | ||
init(dispatch); | ||
init({ target: target, dispatch: dispatch }); | ||
}; | ||
@@ -45,5 +33,7 @@ | ||
var element = component(href)({ state: state, dispatch: dispatch, show: show, next: next }); | ||
var element = component({ state: state, dispatch: dispatch, next: next }); | ||
diff(target, element); | ||
if (element != null) { | ||
diff(target, element); | ||
} | ||
}); | ||
@@ -55,5 +45,5 @@ } | ||
process.nextTick(function () { | ||
callback(target); | ||
callback({ target: target, dispatch: dispatch }); | ||
}); | ||
} | ||
}; |
22
main.js
@@ -1,21 +0,9 @@ | ||
const catchLinks = require('catch-links') | ||
const singlePage = require('single-page') | ||
module.exports = function ({target, store, component, diff, raf}) { | ||
raf = raf != null ? raf : window.requestAnimationFrame | ||
let href | ||
let state = store() | ||
let rafCalled = false | ||
const show = singlePage(function (newHref) { | ||
href = newHref | ||
render() | ||
}) | ||
catchLinks(target, show) | ||
return function (init) { | ||
init(dispatch) | ||
init({target, dispatch}) | ||
} | ||
@@ -36,5 +24,7 @@ | ||
const element = component(href)({state, dispatch, show, next}) | ||
const element = component({state, dispatch, next}) | ||
diff(target, element) | ||
if (element != null) { | ||
diff(target, element) | ||
} | ||
}) | ||
@@ -46,5 +36,5 @@ } | ||
process.nextTick(function () { | ||
callback(target) | ||
callback({target, dispatch}) | ||
}) | ||
} | ||
} |
{ | ||
"name": "@erickmerchant/framework", | ||
"version": "8.0.0", | ||
"version": "9.0.0", | ||
"description": "A simple data down, actions up framework.", | ||
@@ -31,6 +31,3 @@ "main": "dist/main.js", | ||
}, | ||
"dependencies": { | ||
"catch-links": "^2.0.1", | ||
"single-page": "^1.1.0" | ||
} | ||
"dependencies": {} | ||
} |
@@ -36,18 +36,16 @@ # @erickmerchant/framework | ||
function component (href) { | ||
return function ({state, dispatch}) { | ||
return html`<div> | ||
<output>${state}</output> | ||
<br> | ||
<button onclick='${decrement}'>--</button> | ||
<button onclick='${increment}'>++</button> | ||
</p>` | ||
function component ({state, dispatch}) { | ||
return html`<div> | ||
<output>${state}</output> | ||
<br> | ||
<button onclick='${decrement}'>--</button> | ||
<button onclick='${increment}'>++</button> | ||
</p>` | ||
function decrement () { | ||
dispatch('decrement') | ||
} | ||
function decrement () { | ||
dispatch('decrement') | ||
} | ||
function increment () { | ||
dispatch('increment') | ||
} | ||
function increment () { | ||
dispatch('increment') | ||
} | ||
@@ -86,8 +84,2 @@ } | ||
#### show | ||
_show(href)_ | ||
- href: the location will get updated with this and a render will happen | ||
#### next | ||
@@ -101,8 +93,2 @@ | ||
#### next callback | ||
_callback(target)_ | ||
- target: the target passed to [framework](#framework) | ||
#### init | ||
@@ -127,15 +113,6 @@ | ||
_component(href)_ | ||
_component({state, dispatch, next})_ | ||
- href: the current url | ||
Returns the [component result](#component-result) | ||
#### component result | ||
_result({state, dispatch, show, next})_ | ||
- state: see [state](#state) | ||
- dispatch: see [dispatch](#dispatch) | ||
- show: see [show](#show) | ||
- next: see [next](#next) | ||
@@ -150,8 +127,16 @@ | ||
- target: the target passed to [framework](#framework) | ||
- element: the new element returned from the [component result](#component-result) | ||
- element: the new element returned from the [component](#component) | ||
#### next callback | ||
_callback({target, dispatch})_ | ||
- target: the target passed to [framework](#framework) | ||
- dispatch: see [dispatch](#dispatch) | ||
#### init callback | ||
_callback(dispatch)_ | ||
_callback({target, dispatch})_ | ||
- target: the target passed to [framework](#framework) | ||
- dispatch: see [dispatch](#dispatch) | ||
@@ -158,0 +143,0 @@ |
169
test.js
const test = require('tape') | ||
const mockery = require('mockery') | ||
const noop = function () {} | ||
test('test main - set-up', function (t) { | ||
let singlePage | ||
test('test main - init', function (t) { | ||
let theTarget = {} | ||
mockery.enable({ | ||
useCleanCache: true, | ||
warnOnReplace: false, | ||
warnOnUnregistered: false | ||
}) | ||
t.plan(2) | ||
t.plan(4) | ||
mockery.registerMock('single-page', function (callback) { | ||
t.ok(true) | ||
singlePage = callback | ||
return callback | ||
}) | ||
mockery.registerMock('catch-links', function (target, callback) { | ||
t.equal(target, theTarget) | ||
t.equal(callback, singlePage) | ||
}) | ||
require('./main.js')({ | ||
@@ -39,45 +17,23 @@ target: theTarget, | ||
raf: noop | ||
})(function (dispatch) { | ||
t.ok(typeof dispatch, 'function') | ||
})(function ({dispatch, target}) { | ||
t.equal(typeof dispatch, 'function') | ||
t.equal(target, theTarget) | ||
}) | ||
mockery.disable() | ||
}) | ||
test('test main - single-page > render', function (t) { | ||
let singlePage | ||
test('test main - dispatch > render', function (t) { | ||
let theTarget = {} | ||
mockery.enable({ | ||
useCleanCache: true, | ||
warnOnReplace: false, | ||
warnOnUnregistered: false | ||
}) | ||
t.plan(3) | ||
t.plan(5) | ||
mockery.registerMock('single-page', function (callback) { | ||
singlePage = callback | ||
return callback | ||
}) | ||
mockery.registerMock('catch-links', noop) | ||
require('./main.js')({ | ||
target: theTarget, | ||
store: function (state = {}) { | ||
t.deepEqual({}, state) | ||
return state | ||
}, | ||
component: function (app) { | ||
t.deepEqual(Object.keys(app), ['state', 'dispatch', 'next']) | ||
return {} | ||
}, | ||
component: function (href) { | ||
t.equal(href, '/new-href') | ||
return function (app) { | ||
t.deepEqual(Object.keys(app), ['state', 'dispatch', 'show', 'next']) | ||
return {} | ||
} | ||
}, | ||
diff: function (target, newTarget) { | ||
@@ -91,103 +47,30 @@ t.equal(target, theTarget) | ||
} | ||
})(function ({target, dispatch}) { | ||
dispatch() | ||
}) | ||
singlePage('/new-href') | ||
mockery.disable() | ||
}) | ||
test('test main - dispatch', function (t) { | ||
let singlePage | ||
test('test main - next', function (t) { | ||
let theTarget = {} | ||
let dispatchRun = false | ||
let nextRun = false | ||
mockery.enable({ | ||
useCleanCache: true, | ||
warnOnReplace: false, | ||
warnOnUnregistered: false | ||
}) | ||
t.plan(2) | ||
t.plan(5) | ||
mockery.registerMock('single-page', function (callback) { | ||
singlePage = callback | ||
return callback | ||
}) | ||
mockery.registerMock('catch-links', noop) | ||
require('./main.js')({ | ||
target: theTarget, | ||
store: function (state = {}) { | ||
t.ok(true) | ||
return {} | ||
}, | ||
component: function (href) { | ||
return function (app) { | ||
if (!dispatchRun) { | ||
dispatchRun = true | ||
component: function (app) { | ||
if (!nextRun) { | ||
nextRun = true | ||
process.nextTick(function () { | ||
app.dispatch() | ||
app.dispatch() | ||
}, 0) | ||
} | ||
return {} | ||
app.next(function ({target, dispatch}) { | ||
t.equal(typeof dispatch, 'function') | ||
t.equal(target, theTarget) | ||
}) | ||
} | ||
}, | ||
diff: function (target, newTarget) { | ||
t.ok(true) | ||
}, | ||
raf: function (callback) { | ||
process.nextTick(function () { callback() }) | ||
} | ||
}) | ||
singlePage('/new-href') | ||
mockery.disable() | ||
}) | ||
test('test main - next', function (t) { | ||
let singlePage | ||
let theTarget = {} | ||
let nextRun = false | ||
mockery.enable({ | ||
useCleanCache: true, | ||
warnOnReplace: false, | ||
warnOnUnregistered: false | ||
}) | ||
t.plan(1) | ||
mockery.registerMock('single-page', function (callback) { | ||
singlePage = callback | ||
return callback | ||
}) | ||
mockery.registerMock('catch-links', noop) | ||
require('./main.js')({ | ||
target: theTarget, | ||
store: function (state = {}) { | ||
return {} | ||
}, | ||
component: function (href) { | ||
return function (app) { | ||
if (!nextRun) { | ||
nextRun = true | ||
app.next(function (target) { | ||
t.deepEqual(target, theTarget) | ||
}) | ||
} | ||
return {} | ||
} | ||
}, | ||
diff: function (target, newTarget) { | ||
@@ -198,7 +81,5 @@ }, | ||
} | ||
})(function ({target, dispatch}) { | ||
dispatch() | ||
}) | ||
singlePage('/new-href') | ||
mockery.disable() | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
8793
132
153
- Removedcatch-links@^2.0.1
- Removedsingle-page@^1.1.0
- Removedcatch-links@2.0.1(transitive)
- Removedsingle-page@1.1.0(transitive)