Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hibiki v0.3.2 #6

Merged
merged 7 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename hibiki/core library (remove at sign). add callFn to DataCtx. c…
…hange 'colspan' to 'colSpan' for react
  • Loading branch information
sawka committed Feb 23, 2022
commit f5f3a4cd72f81216943969a025aa8eebf9348a29
47 changes: 21 additions & 26 deletions src/datactx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2189,37 +2189,33 @@ function JsonStringify(v : HibikiVal, opts? : {space? : number, noresolve? : boo
}

function evalFnAst(fnAst : any, dataenv : DataEnvironment) : HibikiVal {
let state = dataenv.dbstate;
let stateFn : JSFuncType = null;
let fnName = fnAst.fn.toLowerCase();
let params = evalExprParams(fnAst.params, dataenv);
return callFn(fnName, params, dataenv);
}

function callFn(fnName : string, params : HibikiParamsObj, dataenv : DataEnvironment) : HibikiVal {
if (fnName.startsWith("fn:")) {
fnName = fnName.substr(3);
stateFn = DefaultJSFuncs[fnName];
}
else if (fnName.startsWith("fnx:")) {
fnName = fnName.substr(4);
stateFn = state.JSFuncs[fnName];
let stateFn = DefaultJSFuncs[fnName];
if (stateFn == null) {
throw new Error(sprintf("Invalid function: '%s'", fnName));
}
if (stateFn != null) {
let params = evalExprParams(fnAst.params, dataenv);
if (!stateFn.native) {
params.deepCopy({resolve: true});
}
else if (!stateFn.retainNoAttr) {
params.stripNoAttrs();
}
if (stateFn.paramFn != null) {
return stateFn.paramFn(params, dataenv);
}
else if (stateFn.fn != null) {
return stateFn.fn(...params.posArgs);
}
else {
throw new Error(sprintf("Invalid function: '%s', no function defined", fnAst.fn));
}
if (!stateFn.native) {
params.deepCopy({resolve: true});
}
else if (!stateFn.retainNoAttr) {
params.stripNoAttrs();
}
if (stateFn.paramFn != null) {
return stateFn.paramFn(params, dataenv);
}
else if (stateFn.fn != null) {
return stateFn.fn(...params.posArgs);
}
else {
throw new Error(sprintf("Invalid function: '%s'", fnAst.fn));
throw new Error(sprintf("Invalid function: '%s', no function defined", fnAst.fn));
}
}

Expand Down Expand Up @@ -2627,7 +2623,6 @@ function evalExprAstInternal(exprAst : HExpr, dataenv : DataEnvironment, rtype :
}
else {
console.log("BAD ETYPE", exprAst);
console.trace();
throw new Error(sprintf("Invalid expression etype: '%s'", exprAst.etype));
}
}
Expand Down Expand Up @@ -3370,7 +3365,7 @@ function compareVals(v1 : HibikiVal, v2 : HibikiVal, opts? : CompareOpts) : numb
return sv1.localeCompare(sv2, locale, {numeric: numeric, sensitivity: sensitivity});
}

export {ParsePath, ResolvePath, SetPath, ParsePathThrow, ResolvePathThrow, StringPath, JsonStringify, EvalSimpleExpr, ParseSetPathThrow, ParseSetPath, HibikiBlob, ObjectSetPath, DeepEqual, DeepCopy, CleanVal, DeepCopyTypeSafe, CheckCycle, LValue, BoundLValue, ObjectLValue, ReadOnlyLValue, getShortEMsg, CreateReadOnlyLValue, demobx, BlobFromRRA, ExtBlobFromRRA, isObject, convertSimpleType, ParseStaticCallStatement, evalExprAst, BlobFromBlob, formatVal, ExecuteHandlerBlock, ExecuteHAction, makeIteratorFromExpr, rawAttrStr, getUnmergedAttributeStr, getUnmergedAttributeValPair, SYM_NOATTR, HActionBlock, valToString, valToBool, compileActionStr, FireEvent, makeErrorObj, OpaqueValue, ChildrenVar, Watcher, LambdaValue, blobPrintStr, valToNumber, hibikiTypeOf, JsonReplacerFn, valToAttrStr, resolveLValue, resolveUnmergedCnArray, isUnmerged, resolveUnmergedStyleMap, asStyleMap, asStyleMapFromPair, EvalContextVarsThrow, compareVals, asPrimitive, asArray, asPlainObject, HibikiParamsObj, stripNoAttrShallow, HibikiReactEvent};
export {ParsePath, ResolvePath, SetPath, ParsePathThrow, ResolvePathThrow, StringPath, JsonStringify, EvalSimpleExpr, ParseSetPathThrow, ParseSetPath, HibikiBlob, ObjectSetPath, DeepEqual, DeepCopy, CleanVal, DeepCopyTypeSafe, CheckCycle, LValue, BoundLValue, ObjectLValue, ReadOnlyLValue, getShortEMsg, CreateReadOnlyLValue, demobx, BlobFromRRA, ExtBlobFromRRA, isObject, convertSimpleType, ParseStaticCallStatement, evalExprAst, BlobFromBlob, formatVal, ExecuteHandlerBlock, ExecuteHAction, makeIteratorFromExpr, rawAttrStr, getUnmergedAttributeStr, getUnmergedAttributeValPair, SYM_NOATTR, HActionBlock, valToString, valToBool, compileActionStr, FireEvent, makeErrorObj, OpaqueValue, ChildrenVar, Watcher, LambdaValue, blobPrintStr, valToNumber, hibikiTypeOf, JsonReplacerFn, valToAttrStr, resolveLValue, resolveUnmergedCnArray, isUnmerged, resolveUnmergedStyleMap, asStyleMap, asStyleMapFromPair, EvalContextVarsThrow, compareVals, asPrimitive, asArray, asPlainObject, HibikiParamsObj, stripNoAttrShallow, HibikiReactEvent, callFn};

export type {PathType, HAction, HExpr, HIteratorExpr, ContextVarType, CompareOpts};

4 changes: 4 additions & 0 deletions src/dbctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ class DBCtx {
return nodeStr(this.node);
}

textContent() : string {
return textContent(this.node);
}

resolvePath(path : string, opts? : {rtContext? : string}) : HibikiVal {
opts = opts ?? {};
let rtContext = opts.rtContext ?? "DBCtx.resolvePath";
Expand Down
7 changes: 5 additions & 2 deletions src/nodes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,9 @@ class RawHtmlNode extends React.Component<HibikiReactProps, {}> {
elemProps["download"] = "";
continue;
}
if (k === "colspan") {
k = "colSpan";
}
elemProps[k] = strVal;
}
if (!managedAttrs["value"] && elemProps["value"] == null && ctx.getRawAttr("value") == "") {
Expand Down Expand Up @@ -899,12 +902,12 @@ class SimpleQueryNode extends React.Component<HibikiReactProps, {}> {

function addCoreComponent(name : string, impl : any) {
let comp : LibComponentType = {componentType: "hibiki-native"};
comp.impl = mobx.observable.box(impl, {name: "@hibiki/core/" + name});
comp.impl = mobx.observable.box(impl, {name: "hibiki/core/" + name});
CORE_LIBRARY.libComponents[name] = comp;
}

let CORE_LIBRARY : LibraryType = {
name: "@hibiki/core",
name: "hibiki/core",
libNode: new HibikiNode("#def", {list: []}),
libComponents: {},
importedComponents: {},
Expand Down
20 changes: 19 additions & 1 deletion src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ class DataEnvironment {
return rtn;
}

callFn(fnName : string, p1 : HibikiVal[] | HibikiValObj, p2 : HibikiValObj) : HibikiVal {
let plainObj : HibikiValObj = null;
let [p1Obj, p1IsObj] = DataCtx.asPlainObject(p1, false);
if (p1IsObj) {
plainObj = p1Obj;
}
else {
let [p1Arr, p1IsArr] = DataCtx.asArray(p1, false);
let [p2Obj, p2IsObj] = DataCtx.asPlainObject(p2, false);
plainObj = (p2IsObj ? p2Obj : {});
if (p1IsArr) {
plainObj["*args"] = p1Arr;
}
}
let paramsObj = new DataCtx.HibikiParamsObj(plainObj);
return DataCtx.callFn(fnName, paramsObj, this);
}

resolveRoot(rootName : string, opts?: {caret? : number}) : HibikiValObj | HibikiVal[] {
opts = opts || {};
if (opts.caret != null && opts.caret < 0 || opts.caret > 1) {
Expand Down Expand Up @@ -753,7 +771,7 @@ class ComponentLibrary {
else {
libObj.modules["lib"] = new mreg["lib"](this.state, {libContext: libName});
}
this.importLibrary(libName, "@hibiki/core", null, true);
this.importLibrary(libName, "hibiki/core", null, true);
let importTags = subNodesByTag(libNode, "import-library");
for (let i=0; i<importTags.length; i++) {
let itag = importTags[i];
Expand Down