Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from wheelsmake/dev-versionC
Browse files Browse the repository at this point in the history
Dev version c1.1 merge
  • Loading branch information
ljm12914 authored Sep 9, 2022
2 parents 67130a5 + 0cd5333 commit 40ed8c8
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 49 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dynamic 中没有组件的概念,它直接关注数据本身。你可以把 dy
与 dynamic 的**全部交互**(包括 HTML 模板)均可以通过 JavaScript 完成,dynamic 的 HTML 模板语法只有三个:

- 插入单向绑定属性:下划线加横线 `_- -_`
- 可以用 [`new Dynamic().addExport()`](#addExport) 替代。
- 可以用 [`Dynamic().addExport()`](#addExport) 替代。

- 插入双向绑定属性:下划线加冒号 `_: :_`
- 双向绑定的使用时机非常少,仅在表单元素或 DOM 编辑场景下有用。但是 dynamic 支持对元素 attribute 的值和元素文本内容进行双向绑定。对 attribute 的键名进行双向绑定是**不合理的**——dynamic 要怎么知道哪个 attribute 是之前那个呢?
Expand Down Expand Up @@ -156,7 +156,7 @@ Vue.createApp({
dynamic 实现方式的 JavaScript:

```javascript
const dy = new Dynamic("#app");
const dy = Dynamic("#app");
const list = ["a","b","c"];
dy.data.items = function(){
const result = [];
Expand Down Expand Up @@ -214,7 +214,7 @@ dy.addMethods({
## 创建 dynamic 实例

```typescript
const dy = new Dynamic(/*Element或css 选择符*/);
const dy = Dynamic(/*Element或css 选择符*/);
```

传入的唯一参数为根节点,根节点**也会**被该实例管理。
Expand All @@ -240,7 +240,7 @@ dynamic **强依赖**于其作用域内 DOM 的不变性,也因此才可以实
```

```javascript
var dy = new Dynamic("#el");
var dy = Dynamic("#el");
Dynamic.e("#no").innerText = "";
```

Expand Down
27 changes: 11 additions & 16 deletions dist/dynamic.js

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

2 changes: 1 addition & 1 deletion dist/dynamic.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dynamic.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dynamic.min.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/types/dynamic/src/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export default class App {
#private;
constructor(rootNode: Elementy);
get rootNode(): Element;
get dOProcessorStore(): WeakMap<Node, MRProcessorFn>;
get data(): anyObject;
get _(): anyObject;
addExport(dataProperty: string, func: exportFunc, target: Node): shouldExportA;
Expand Down
2 changes: 1 addition & 1 deletion dist/types/dynamic/src/app.d.ts.map

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

3 changes: 1 addition & 2 deletions dist/types/dynamic/src/dynamic.export.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import App from "./app";
declare function Dynamic(rootNode: Elementy): App;
declare const Dynamic: Dynamic;
export default Dynamic;
//# sourceMappingURL=dynamic.export.d.ts.map
2 changes: 1 addition & 1 deletion dist/types/dynamic/src/dynamic.export.d.ts.map

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 @@ -12,4 +12,4 @@
"webpack-cli": "^4.10.0",
"webpack-utf8-bom": "^1.4.0"
}
}
}
4 changes: 2 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class App{
#aOProcessorStore = new WeakMap<Element, MRProcessorFn>();
#dOProcessorStore = new WeakMap<Node, MRProcessorFn>();
#cOProcessorStore = new WeakMap<Element, MRProcessorFn>();
get dOProcessorStore(){return this.#dOProcessorStore};
//get dOProcessorStore(){return this.#dOProcessorStore};
//简单的DOM监控回调机制,全看对面MRProcessorFn设计得如何
#observer :MutationObserver = new MutationObserver((records :MutationRecord[])=>{
for(let i = 0; i < records.length; i++){
Expand Down Expand Up @@ -161,7 +161,7 @@ export default class App{
const shouldUpdateThis = lUtils.data.detectShouldUpdate(Function.prototype.toString.call(newValue));
//console.log(shouldUpdateThis, property);
for(let i = 0; i < shouldUpdateThis.length; i++){
//如果函数中访问了还没有创建的属性,那么我们只能去创建它,因为shouldUpdateA不能在之后补上。其实正确的做法是先不创建的
//fixme:如果函数中访问了还没有创建的属性,那么我们只能去创建它,因为shouldUpdateA不能在之后补上。其实正确的做法是先不创建的
if(!(shouldUpdateThis[i] in sharpData)) proxy[shouldUpdateThis[i]] = undefined;
if(sharpData[shouldUpdateThis[i]].shouldUpdates.indexOf(property) == -1) sharpData[shouldUpdateThis[i]].shouldUpdates.push(property);
}
Expand Down
30 changes: 14 additions & 16 deletions src/dynamic.export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,23 @@ function __enableDevTools__() :void{
}

//构造导出对象
function Dynamic(rootNode :Elementy){return new App(rootNode);}
((obj :anyObject)=>{
for(let i in obj) (Dynamic as anyObject)[i] = obj[i];
})({
const Dynamic :Dynamic = (rootNode :Elementy)=>{return new App(rootNode);}
//引入模块
template, spa, manifest,
Dynamic.template = template;
Dynamic.spa = spa;
Dynamic.manifest = manifest;
//工具方法
e(s: string, scope?: Element | Document) :Node | Node[]{return utils.element.e(s, scope);},
render(args :{
HTML :string | Element | HTMLCollection | Element[] | Node | NodeList | Node[],
element :Element, insertAfter? :boolean, append? :boolean
}) :Node[]{return utils.element.render(args.HTML, args.element, args.insertAfter, args.append);},
toHTML(HTML :string) :Node[]{return utils.element.toHTML(HTML)},
hatch(element :Element, remove? :boolean) :Node[]{return utils.element.hatch(element, remove);},
compose(){}, //todo:
Dynamic.e = (s: string, scope?: Element | Document) :Node | Node[]=>{return utils.element.e(s, scope);};
Dynamic.render = (args :{
HTML :string | Element | HTMLCollection | Element[] | Node | NodeList | Node[];
element :Element, insertAfter? :boolean, append? :boolean
}) :Node[]=>{return utils.element.render(args.HTML, args.element, args.insertAfter, args.append);};
Dynamic.toHTML = (HTML :string) :Node[]=>{return utils.element.toHTML(HTML)};
Dynamic.hatch = (element :Element, remove? :boolean) :Node[]=>{return utils.element.hatch(element, remove);};
Dynamic.compose = ()=>{}; //todo:
//hack
__disableDevTools__,
__enableDevTools__
});
Dynamic.__disableDevTools__ = __disableDevTools__;
Dynamic.__enableDevTools__ = __enableDevTools__;

//导出
utils.generic.constantize(Dynamic);
Expand Down
19 changes: 18 additions & 1 deletion src/types/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,21 @@ type anyObject = Record<string, any>;
type kvObject = Record<string, string | undefined | null>;
type SSkvObject = Record<string, string>;
type Elementy = Element | string;
type Nody = Node | string;
type Nody = Node | string;
interface Dynamic extends Function{
template: typeof import("../template");
spa: typeof import("../spa");
manifest: typeof import("../manifest");
e(s: string, scope?: Element | Document): Node | Node[];
render(args: {
HTML: string | Element | HTMLCollection | Element[] | Node | NodeList | Node[];
element: Element;
insertAfter?: boolean;
append?: boolean;
}): Node[];
toHTML(HTML: string): Node[];
hatch(element: Element, remove?: boolean): Node[];
compose(): void;
__disableDevTools__(): void;
__enableDevTools__(): void;
}
2 changes: 1 addition & 1 deletion tests/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var dy = new Dynamic("#app");
var dy = Dynamic("#app");
dy.data.name = "dynamic";
dy.data.op = function(){
this.few = '"``"';
Expand Down

0 comments on commit 40ed8c8

Please sign in to comment.