@dwightbcoder/action-ui
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "@dwightbcoder/action-ui", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Action UI is a Javascript framework for building event-base user interfaces", | ||
"main": "src/index.js", | ||
"main": "dist/index.js", | ||
"directories": { | ||
"example": "example" | ||
}, | ||
"prepublish": "npm run build", | ||
"scripts": { | ||
"rollup": "rollup src/index.js --format iife --name ActionUI --file src/bundle.js", | ||
"babel:dev": "NODE_ENV=dev babel src/bundle.js -d dist && mv dist/bundle.js dist/action-ui.js", | ||
"babel:prod": "NODE_ENV=production babel src/bundle.js -d dist && mv dist/bundle.js dist/action-ui.min.js", | ||
"build": "npm run rollup && npm run babel:dev && npm run babel:prod && cp -a src dist/es6", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
@@ -31,3 +36,10 @@ }, | ||
}, | ||
"homepage": "https://github.com/dwightbcoder/action-ui#readme" | ||
"homepage": "https://github.com/dwightbcoder/action-ui#readme", | ||
"devDependencies": { | ||
"@babel/cli": "^7.6.2", | ||
"@babel/core": "^7.6.2", | ||
"@babel/preset-env": "^7.6.2", | ||
"babel-preset-minify": "^0.5.1" | ||
}, | ||
"dependencies": {} | ||
} |
@@ -9,2 +9,3 @@ import * as Util from './modules/util.js' | ||
export { View } from './modules/view.js' | ||
export { ViewFile } from './modules/view.file.js' | ||
export { ViewHandlebars } from './modules/view.handlebars.js' |
import * as Util from './util.js' | ||
import { Controller } from './controller.js' | ||
import { View } from './view.js' | ||
import { ViewFile } from './view.file.js' | ||
import { ViewHandlebars } from './view.handlebars.js' | ||
@@ -12,3 +13,3 @@ | ||
this._instance = {} | ||
this.view = (view instanceof View) ? view : new View(view) | ||
this.view = (view instanceof View) ? view : new ViewFile(view) | ||
this.state = state | ||
@@ -32,5 +33,5 @@ window.addEventListener('popstate', this.changeState.bind(this)) | ||
controller = this.controllerName(pathController) | ||
pathMethod = path[0] | ||
pathMethod = route == '/' ? _options.defaultMethod : path[0] | ||
} | ||
if (! this._instance[controller]) | ||
@@ -50,8 +51,13 @@ { | ||
let result = null | ||
let template = pathController + '/' + pathMethod | ||
let view = pathController + '/' + pathMethod | ||
let method = Util.camelCase(pathMethod) | ||
if ( this._instance[controller].view instanceof ViewHandlebars) | ||
if ( this._instance[controller].view instanceof ViewFile) | ||
{ | ||
this._instance[controller].view.html = template | ||
this._instance[controller].view.file = view | ||
} | ||
else if ( this._instance[controller].view instanceof ViewHandlebars) | ||
{ | ||
this._instance[controller].view.html = view | ||
} | ||
@@ -64,3 +70,3 @@ if (_options.autoload && ! (this._instance[controller][method] instanceof Function)) | ||
model.dev = location.host == _options.devHost | ||
model.view = template | ||
model.view = view | ||
model.controller = pathController | ||
@@ -147,4 +153,8 @@ model.method = pathMethod | ||
{ | ||
if ( this._instance[controller].view instanceof ViewHandlebars) | ||
if ( this._instance[controller].view instanceof ViewFile) | ||
{ | ||
this._instance[controller].view.file = _options.errorView | ||
} | ||
else if ( this._instance[controller].view instanceof ViewHandlebars) | ||
{ | ||
this._instance[controller].view.html = _options.errorView | ||
@@ -151,0 +161,0 @@ } |
@@ -1,2 +0,3 @@ | ||
import { View } from './view.js' | ||
import { ViewFile } from './view.file.js' | ||
import { deepAssign } from './util.js' | ||
@@ -8,31 +9,15 @@ /** | ||
*/ | ||
class ViewHandlebars extends View | ||
class ViewHandlebars extends ViewFile | ||
{ | ||
constructor(name, template, model) | ||
{ | ||
if (arguments.length == 2) | ||
{ | ||
model = template | ||
template = undefined | ||
} | ||
if (!template) | ||
{ | ||
template = name | ||
} | ||
super(name, template, model) | ||
} | ||
render() | ||
{ | ||
if ( ViewHandlebars.options.verbose ) console.info( 'ViewHandlebars.render()', this.name, {view:this} ) | ||
if ( _options.verbose ) console.info( 'ViewHandlebars.render()', this.name, {view:this} ) | ||
var _promise = null | ||
if ('string' == (typeof this._html)) | ||
if (this._html == null) | ||
{ | ||
if (Handlebars.templates && Handlebars.templates[this._html]) | ||
if (Handlebars.templates && Handlebars.templates[this.file]) | ||
{ | ||
this._html = Handlebars.templates[this._html] | ||
this._html = Handlebars.templates[this.file] | ||
_promise = Promise.resolve() | ||
@@ -42,7 +27,3 @@ } | ||
{ | ||
let template = this._html + '.' + ViewHandlebars.options.extension | ||
_promise = fetch(ViewHandlebars.options.basePath + template) | ||
.then(response => { if (response.ok) return response.text() }) | ||
.then(html => this._html = Handlebars.compile(html)) | ||
.catch(e => { throw new Error('Template not found: ' + template) }) | ||
_promise = this.fetch().then(() => this._html = Handlebars.compile(this._html)) | ||
} | ||
@@ -60,19 +41,12 @@ } | ||
// View factory | ||
static create(options) | ||
{ | ||
if ( options.template ) | ||
{ | ||
options.template = options.name | ||
} | ||
static get options() { return _options } | ||
static set options(value) { deepAssign(_options, value) } | ||
return new ViewHandlebars(options.name, options.template, options.model) | ||
} | ||
// #endregion | ||
} | ||
ViewHandlebars.options.basePath = '' | ||
let _options = {} | ||
ViewHandlebars.options = ViewFile.options | ||
ViewHandlebars.options.extension = 'hbs' | ||
export { ViewHandlebars } |
@@ -1,2 +0,2 @@ | ||
import * as Util from './util.js' | ||
import { deepAssign } from './util.js' | ||
import { Model } from './model.js' | ||
@@ -113,3 +113,3 @@ | ||
static get options() { return _options } | ||
static set options(value) { Util.deepAssign(_options, value) } | ||
static set options(value) { deepAssign(_options, value) } | ||
@@ -116,0 +116,0 @@ // #endregion |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
229770
40
6428
4
33