Skip to content

Commit

Permalink
- support functional ctx parameter for returning customized contex…
Browse files Browse the repository at this point in the history
…t especially useful for nested views.
  • Loading branch information
zbryikt committed Sep 19, 2022
1 parent 9f3acae commit 1e5449a
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
- only update one of module or window
- remove `setContext()` and `setCtx()`, in favor of `ctx()`.

## v1.3.0

- support functional `ctx` parameter for returning customized context especially useful for nested views.


## v1.2.1

- fix bug: `ctx()` should test argument's existence with `arguments.length`
Expand Down
7 changes: 7 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
this.root.textContent = '';
this.root.appendChild(this.template.cloneNode(true));
}
if (typeof this._ctx === 'function') {
this._ctx = this._ctx({
node: this.root,
ctxs: this._ctxs,
views: this.views
});
}
this.update();
names = {};
for (i$ = 0, len$ = (ref$ = [(fn$.call(this))].concat([(fn1$.call(this))], [(fn2$.call(this))], [(fn3$.call(this))], [(fn4$.call(this))], (fn5$.call(this)).map(fn6$))).length; i$ < len$; ++i$) {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"browser": "dist/index.min.js",
"main": "dist/index.min.js",
"description": "view template micro framework",
"version": "1.2.1",
"version": "1.3.0",
"files": [
"dist/**/*"
],
Expand Down
1 change: 1 addition & 0 deletions src/ldview.ls
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ldview = (opt = {}) ->
if (@template = opt.template) =>
@root.textContent = ''
@root.appendChild @template.cloneNode(true)
if typeof(@_ctx) == \function => @_ctx = @_ctx {node: @root, ctxs: @_ctxs, views: @views}

@update!

Expand Down
7 changes: 7 additions & 0 deletions web/static/assets/lib/ldview/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
this.root.textContent = '';
this.root.appendChild(this.template.cloneNode(true));
}
if (typeof this._ctx === 'function') {
this._ctx = this._ctx({
node: this.root,
ctxs: this._ctxs,
views: this.views
});
}
this.update();
names = {};
for (i$ = 0, len$ = (ref$ = [(fn$.call(this))].concat([(fn1$.call(this))], [(fn2$.call(this))], [(fn3$.call(this))], [(fn4$.call(this))], (fn5$.call(this)).map(fn6$))).length; i$ < len$; ++i$) {
Expand Down
2 changes: 1 addition & 1 deletion web/static/assets/lib/ldview/dev/index.min.js

Large diffs are not rendered by default.

0 comments on commit 1e5449a

Please sign in to comment.