-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(build): compile imba and generate d.ts files
- Loading branch information
Showing
8 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Object.defineProperty(exports, "__esModule", {value: true}); | ||
|
||
/*body*/ | ||
var _$readPropsφ = require('./readProps'/*$path$*/); | ||
|
||
exports.readProps = _$readPropsφ.readProps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Object.defineProperty(exports, "__esModule", {value: true}); | ||
|
||
/*body*/ | ||
var _$ReadPropsφ = require('../ReadProps'/*$path$*/); | ||
|
||
function readProps(component){ | ||
|
||
return _$ReadPropsφ.ReadProps.persist(component); | ||
}; | ||
exports.readProps = readProps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Object.defineProperty(exports, "__esModule", {value: true}); | ||
|
||
/*body*/ | ||
class ReadProps { | ||
|
||
static persist(component){ | ||
var φ; | ||
|
||
try { | ||
|
||
return JSON.parse(((φ = component.attributes.props.nodeValue) != null) ? (φ) : '{}'); | ||
} catch (φ2) { | ||
|
||
return {}; | ||
}; | ||
} | ||
}; | ||
exports.ReadProps = ReadProps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
const Ψ__initor__ = Symbol.for('#__initor__'), Ψ__inited__ = Symbol.for('#__inited__'), Ψ__init__ = Symbol.for('#__init__'), ΨbeforeReconcile = Symbol.for('#beforeReconcile'), ΨplaceChild = Symbol.for('#placeChild'), ΨafterReconcile = Symbol.for('#afterReconcile'); | ||
var εSELF = Symbol(), εT = Symbol(); | ||
const {styles: imba_styles, get_document: imba_get_document, Component: imba_Component, createComponent: imba_createComponent, createLiveFragment: imba_createLiveFragment, defineTag: imba_defineTag} = require('imba'/*$path$*/); | ||
Object.defineProperty(exports, "__esModule", {value: true}); | ||
|
||
/*body*/ | ||
let stateTree = null; | ||
let stateEvent = null; | ||
|
||
class State { | ||
|
||
/** | ||
@param {Object} state | ||
*/ | ||
constructor(state = {}){ | ||
|
||
return new Proxy(state,{ | ||
get: function(target,prop) { | ||
|
||
if (typeof target[prop] === 'function' && prop == 'get') { | ||
|
||
return function(...args) { | ||
|
||
return target[args[0]]; | ||
}; | ||
} else if (typeof target[prop] === 'function' && prop == 'set') { | ||
|
||
return function(...args) { | ||
|
||
const oldValue = target[args[0]]; | ||
|
||
target[args[0]] = args[1]; | ||
target.set(args[0],args[1],oldValue); | ||
|
||
return target[args[0]]; | ||
}; | ||
} else { | ||
|
||
return target[prop]; | ||
}; | ||
}, | ||
|
||
set: function(target,prop,value) { | ||
|
||
return target[prop] = value; | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
class EventBus { | ||
[Ψ__init__]($$ = null){ | ||
this.eventTarget = $$ ? $$.eventTarget : undefined; | ||
|
||
} | ||
/** | ||
@param {String} description | ||
*/ | ||
constructor(description = 'state-event'){ | ||
this[Ψ__init__](); | ||
this.eventTarget = imba_get_document().appendChild(imba_get_document().createComment(description)); | ||
} | ||
|
||
on(type,listener){ | ||
|
||
return this.eventTarget.addEventListener(type,listener); | ||
} | ||
|
||
emit(type,detail){ | ||
|
||
return this.eventTarget.dispatchEvent(new CustomEvent(type,{detail: detail})); | ||
} | ||
}; | ||
|
||
function createAppState(state){ | ||
|
||
return stateTree = new State(state); | ||
}; | ||
|
||
function hasState(){ | ||
|
||
return stateTree !== null; | ||
}; | ||
|
||
class InitializeState extends imba_Component { | ||
|
||
render(){ | ||
var τSELF, ιSELF, ΔSELF, τT, φ; | ||
|
||
τSELF=this; | ||
τSELF[ΨbeforeReconcile](); | ||
(ιSELF=ΔSELF=1,τSELF[εSELF] === 1) || (ιSELF=ΔSELF=0,τSELF[εSELF]=1); | ||
τT=τSELF.__slots.__; | ||
(τSELF[εT] = τSELF[ΨplaceChild](τT,384,τSELF[εT])); | ||
; | ||
τSELF[ΨafterReconcile](ΔSELF); | ||
|
||
|
||
if (this.attributes.state && imba_get_document().appendChild) { | ||
|
||
stateEvent = new EventBus; | ||
|
||
const state = ((φ = this.attributes.state.nodeValue) != null) ? (φ) : '{}'; | ||
|
||
return createAppState( | ||
Object.assign( | ||
JSON.parse(state), | ||
{ | ||
get: function(prop) { return null; }, | ||
set: function(prop,value,old) { | ||
|
||
return stateEvent.emit('changed',{ | ||
prop: prop, | ||
value: value, | ||
old: old | ||
}); | ||
} | ||
} | ||
) | ||
); | ||
}; | ||
} | ||
}; imba_defineTag('initialize-state-v1jz1w-ah',InitializeState,{}); | ||
|
||
/** | ||
@param {String[]} props | ||
@param {Function} callback | ||
*/ | ||
function watch(props = [],callback){ | ||
|
||
if (!stateEvent) { return }; | ||
|
||
return stateEvent.on('changed',function(event) { | ||
|
||
if (props.includes(event.detail.prop)) { | ||
|
||
return callback(event.detail.value,event.detail.old,event.detail.prop); | ||
}; | ||
}); | ||
}; | ||
|
||
exports.createAppState = createAppState; | ||
exports.EventBus = EventBus; | ||
exports.hasState = hasState; | ||
exports.InitializeState = InitializeState; | ||
exports.event = stateEvent; | ||
exports.state = stateTree; | ||
exports.watch = watch; | ||
|
||
imba_styles.register('v1jz1w',` | ||
initialize-state-v1jz1w-ah { display:block; } | ||
`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Object.defineProperty(exports, "__esModule", {value: true}); | ||
|
||
/*body*/ | ||
var _$readPropsφ = require('./Support/Helpers/readProps'/*$path$*/); | ||
var _$ReadPropsφ = require('./Support/ReadProps'/*$path$*/); | ||
|
||
exports.readProps = _$readPropsφ.readProps; | ||
exports.ReadProps = _$ReadPropsφ.ReadProps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export function readProps(component: any): any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class ReadProps { | ||
static persist(component: any): any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { readProps } from "./Support/Helpers/readProps"; | ||
import { ReadProps } from "./Support/ReadProps"; | ||
export { readProps, ReadProps }; |