-
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.
Merge pull request #4 from ChristoPy/develop
Version v0.0.2
- Loading branch information
Showing
7 changed files
with
79 additions
and
69 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
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
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
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,7 @@ | ||
import directives from './directives.js' | ||
|
||
export default (model) => { | ||
let runInnerDirective = directives(model) | ||
|
||
return (model, path) => runInnerDirective(model, path) | ||
} |
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 |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import model from "./model.js" | ||
import { attachDirectives } from "./directives.js" | ||
import dom from "./dom.js" | ||
|
||
export default (data) => { | ||
let runInnerDirective = null | ||
let updateDOM = null | ||
|
||
const app = model(data, () => runInnerDirective()) | ||
|
||
runInnerDirective = attachDirectives(app) | ||
const app = model(data, (path) => updateDOM(app, path)) | ||
updateDOM = dom(app) | ||
|
||
return app | ||
} |
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 |
---|---|---|
@@ -1,30 +1,8 @@ | ||
const getAll = (name) => | ||
document.querySelectorAll(name ? `[k-model="${name}"]` : "[k-model]") | ||
|
||
const updateModel = (value, name) => | ||
getAll(name).forEach( | ||
(element) => | ||
(element.value = | ||
typeof value !== "string" ? JSON.stringify(value) : value) | ||
) | ||
|
||
const setupModels = (model) => { | ||
getAll().forEach((element) => { | ||
const modelName = element.getAttribute("k-model") | ||
updateModel(model[modelName] || "", modelName) | ||
element.oninput = () => (model[modelName] = element.value) | ||
}) | ||
return model | ||
} | ||
|
||
export default (data, callback) => setupModels( | ||
new Proxy(data, { | ||
get: (target, path) => target[path], | ||
set: (target, path, value) => { | ||
data[path] = value | ||
updateModel(data[path], path) | ||
callback(data) | ||
return true | ||
} | ||
}) | ||
) | ||
export default (data, callback) => new Proxy(data, { | ||
get: (target, path) => target[path], | ||
set: (_, path, value) => { | ||
data[path] = value | ||
callback(path) | ||
return true | ||
} | ||
}) |
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,7 @@ | ||
export const valueToText = (data, value) => { | ||
if (typeof value === "function") return value.call(data) | ||
if (typeof value === "object") return JSON.stringify(value) | ||
return value | ||
} | ||
|
||
export const get = (selector) => [...document.querySelectorAll(selector)] |