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

New materialization #58

Merged
merged 21 commits into from
Apr 27, 2020
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ app.rb
todomvc/node_modules/*
todomvc/js/app.js
node_modules/*
package-lock.json
package-lock.json
test.*
21 changes: 21 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
=== 1.3.0

1. update binding: Implement new Materialization process

2. change behaviour of `Sirus.BaseModel.reset` methods

3. update todo-mvc example

4. rename Adapter property method to `get_properties`

5. improve internal logging with `Adapter.as_string` method

6. remove `running` property

7. rename `logging` to `enable_logging`


=== 1.2.0

1. improve logging

=== 1.0.0

1. update docs, todo-app
Expand Down
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ task :build do
comment_header version adapter vanilla_js_adapter
logger internal promise utils
sirius validators observer
view base_model transformer collection
view base_model collection materialization
))

core_files = coffee(src, %w(
Expand Down Expand Up @@ -153,7 +153,7 @@ namespace :todo do
end

desc "TODOApp compile"
task :compile => [:build] do
task :compile do #=> [:build] do
app = 'todomvc'
app_files = coffee(app, [
"js/utils/template",
Expand All @@ -164,7 +164,7 @@ namespace :todo do
"js/utils/renderer",
"js/controllers/main_controller",
"js/controllers/todo_controller",
"js/controllers/bottom_controller",
"js/controllers/additional_info_controller",
"js/controllers/link_controller",
"js/app"
])
Expand Down
124 changes: 59 additions & 65 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,40 @@ person.find("name", "Joe").to_json() # => {"id" : "g-u-i-d", "name" : "Joe", "ag

[more about collections](https://github.com/fntz/sirius/wiki/Collections)

### 8. Binding
### 8. Binding (Materialization)

Support binding: view to model, view to view, model to view, or model|view to function.
And ot them support all strategies (how to change a content or an attribute) or transform (how to transform a value) methods.
Supported binding:
1. view to model
2. view to view
3. model to view
4. or model|view to function.

#### View To Model

```coffee
# view
<div id="my-input">
<input type="text" />
</div>

# model
class MyModel extends Sirius.BaseModel
@attrs: ["id", "name"]

model = new MyModel()
view = new Sirius.View("#my-input")

# and now materialize!
Materializer.build(view, model) # from view to model
.field((v) -> v.zoom("input"))
.to((m) -> m.name) # or just .to('name')
.transform((result) -> "#{result.text}!")
.run()

```

#### View To View
```coffee
# view to view
# html

# view1
<div id="element">
Expand All @@ -245,76 +271,44 @@ And ot them support all strategies (how to change a content or an attribute) or
view1 = new Sirius.View("#element")
view2 = new Sirius.View("#my-input")

materializer = {
to: [{
from: 'input'
selector: 'p'
with: (new_value, selector, view, attribute) ->
view.zoom(selector).render(new_value).swap(attribute)
}]
}
Sirius.Materializer.build(view2, view1) # from view2 to view1
.field("input") # or field((view) -> view.zoom("input"))
.to('p') # the same ^
.handle((view, result) -> # you can define own handler
view.render(result.text).swap() # default
)
.run()

view2.bind(vew1, materializer)
```

#### Model to View

```coffee
# view to model
# html
<div id="my-input">
<input type="text" />
# model
class MyModel extends Sirius.BaseModel
@attrs: ["name"]
@validate:
name:
length: min: 3, max: 10

# view
<div id="view">
<div class="model-name"></div>
<span class="model-errors"></span>
</div>

model = new MyModel()
view = new Sirius.View("#my-input")
materializer = {
"input": {
to: 'title'
from: 'text'
with: (new_value, view, selector, from, event_target) ->
new_value
}
}
view.bind(model, materializer)
model = new MyModel()
view = new Sirius.View("#view")


# and then fill input, and check

model.title() # => your input
Sirius.Materializer.build(model, view)
.field((m) -> m.name)
.to('.model-name')
.field((m) -> m.errors.name.length) # path to validator
.to('.model-errors')
.run()

```

```coffee
# model to view

<div id="element">
<p></p>
</div>

model = new MyModel() # [id, title]
view = new Sirius.View("#element")

materializer = {
"title": {
to: 'p'
attr: 'text'
via: (new_value, selector, view, attribute) ->
view.zoom(selector).render(new_value).swap(attribute)
}
}

model.bind(view, materializer)

# and then in application:

model.title("new title")

# and new html

<div id="element">
<p>new title</p>
</div>

```

[more about binding](https://github.com/fntz/sirius/wiki/Binding)

Expand Down
15 changes: 8 additions & 7 deletions jquery_adapter.min.js

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

6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@
"prototypejs_adapter.min.js"
],
"devDependencies": {
"codo": "2.0.9",
"coffeescript": "2.2.1"
},
"scripts": {
"doc": "cake doc"
},
"main": "sirius.min.js",
"version": "1.2.0",
"version": "1.3.0",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
11 changes: 6 additions & 5 deletions prototypejs_adapter.min.js

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

Loading