fntz / sirius Goto Github PK
View Code? Open in Web Editor NEWModern coffeescript/javascript framework
License: MIT License
Modern coffeescript/javascript framework
License: MIT License
class Model extends Sirius.BaseModel
@attrs: ["id"]
count: 0
view = new Sirius.View("elem")
model = new Model()
# insead of
view.bind(model, 'count', transform: (x) -> ...)
# need
view.bind(model,
'div#id': {from: 'count', transform: '', ...}
)
When we use coffee, we write:
class FooModel exstends Sirius.BaseModel
@attr: ['id', 'title']
@validate: ...
But it code dirty for javascript, need some like this
var FooModel = Sirius.BaseModel.define_model({
'attr': ['id', 'title'],
'validate' : ...
some_method: function() {}
})
now redirect work like: `window.location.hash = "#/other-page"
need work with history pushState
sirius-core include only routing support (with logger of course) without models, views, and another parts of framework
BaseModel include many methods, possible with coffee define several modules:
Validators, Binding, Versioning, Serialize.
and use as
class Model extends Sirius.BaseModel
include Validators
include Binding
class MyModel extends Sirius.BaseModel
@attrs: ["id", "firstName", "secondName"]
myCollection = new Sirius.Collection(MyModel, [], {
index: ["id", "firstName"]
})
example:
<div id="element">
<span class="some-class"></span>
</div>
Then:
view = new Sirius.View("#element")
view.zoom(".some-class").render("foo").swap() # => <span class="some-class">foo</span>
need add skip
options for BaseModel
.
// json response
{id: 1, foo: test, bar: test1}
class MyModel extends Sirius.BaseModel
@attrs: ["id", "fo"]
at the current moment, when instance model MyModel(json) -> error. undefined field bar
.
but with skip
option -> new instance without error.
problem:
model knew how to view should be applied for it (the main troubles with checkbox, radio from view part, and with arrays from model part)
solution (at first glance)
<form id="my-form">
<input type=text name="email" />
<input type=checkbox name="remember-me" />
</form>
MyModel extends Sirius.BaseModel
@attrs: ["email", "remember_me"]
my_form_view = new Sirius.View("#my-form")
model = new MyModel()
model.bind(my_form_view).via(transformer)
transformer = Sirius.Transformer(
"input[name='email']": {
to: 'email' # just a text field
},
"input[type='checkbox']": {
to: "remember_me"
via: (html_element, value) ->
value # just a boolean value
}
)
Because View
should know nothing about Model
, and the same still valid for Model
Generate default binding i.e. i do not want write every time how to transform text field into text attribute for Model
New Logger name: Transformer
I think need add some validation: check that all html elements are present in View
, and check that all attributes are present in model
situation
class MyMode
@attrs: [{"remember_me" : "of-course"]
view = ...
model = ...
transformer =
{
"input[type='checkbox']": {
to: "remember_me"
via: (html_element, value) ->
# value is boolean are you remember?
value
}
}
As you can see, that in first moment in model we have remember_me
as String
class, but from transformer in model will be set Boolean
.
solution: TypeError
# for example MyModel with attr: title and validator for title -> length: min: 4
m = new MyModel()
m.title("foo")
m.is_valid() # => false
m.title("foo1")
m.is_valid() # => true
m.reset() # or reset('title'), or reset('attr1', 'attr2', 'attr3')
m.title() # => null
m.is_valid() # => false
class MyModel extends Sirius.BaseModel
@attrs: ["title"]
@versions: 3
m = new MyModel()
m.title("foo")
m.title("baz")
m.title("bar")
m.title() # => bar
m.rollback() # => bar
m.versions() # => [foo, baz, bar]
m.title("qux")
m.versions() # => [baz, bar, qux]
m.rollback(0)
m.title() # => baz
m.versions() # => [bar, qux, baz]
# current version on last
example
c = {
action: (a,b,c) -> # pass 1 argument
}
"app:run" : (a,b,c) -> #pass 3 arguments
# but when
"app:run" : controller: c, action: "action"
route = {
"scheduler 1s 10s" : controller: MyScheduler, action: every_10s
"once 1s 10s": controller: MyScheduler, ction: once_10s
}
# 1s - wait
# 10s - every
# instead of
Sirius.Application.get_logger()
# transform to
Sirius.Application.get_logger("class_name")
# and tranform log to
[LEVEL] [SOURCE] [Message]
q?
log_format ?
when we call redirect method: redirect("/path")
it not call url function for it.
i think the best approach
Sirius.App.run
ignore_not_matched_urls: true
m = new MyModel()
v = new Sirius.View("#span")
m.bind2(v);
# and then update title
m.title("new title")
# html
<span id="span" data-bind-view-from='title' data-bind-to='title'></span>
need detect this case and when set new value, unbind model from view or view from model. and then bind again
new Sirius.View
must return already create view, if it created.
# binding
model.bind(view, {
"errors.title.presence" : {to: 'span'}
})
# and has no effect
model.set_error('title', 'presence', 'title is not valid')
for usage some methods in controllers like: redirect
need wrap each Controller#action
into own method;
also need allow user create own wrap function:
app = Sirius.Appliction.create
wrapper: MyWrapper
where
MyWrapper =
log: (url, cotnroller) ->
my_redirect: (url, controller) ->
post: (url, controller, params) ->
then in code
MyController =
action: (params) ->
log "my action start with params: ${params}"
response = post(url, params)
if !response
my_redirect('404")
else
my_view_render(response)
related #33
Must be:
model.to_json(title, id) # { :attr: "" }
and root
must be deprecated
instead of different raw js objects like:
{
"input": {
from: "data-id"
to: "foo"
with: () ->
}
}
need to provide classes and dsl over it for more well and convenient way to use binding
view attributes should be wrapped to classes:
instead of "data-class" => view_attr("data-class")
"text" => view_attr(content)
FromViewToModelMaterializer(input: View, output: BaseModel.attr, zoomed_attr, with: Function)
Q:
dsl should be:
new Mode().binding.id().to(view.zoom("input").with(() -> )
#
view.zoom("input").from(view_attribute).to(model.binding.id).with(() -> )
# or
binding.from(view.zoom("input").to(model.id).with(() -> )
^ dsl should be provided
automatically convert T <: BaseModel to View, just an idea:
m = new MyMode() # id, name, ...
# <div id="some-id">
# <span class="title"></span>
# </div>
m.to_view("#some-id").
with({
"title": "span.title"
"id": {to: "span.title", strategy: (zoomed_view, model): ->
# zoomed_view = View("#some-id").zoom("span.title")
zoomed_view.set_data_element("data-id", model.id())
}
}).on_remove((view)) # or just .build()
.buil()
need add to Collection next methods:
map, collect, collectFirst
some code at the current moment, (for example set default values when bind) call stackoverflow error. Because ie9 does not support MutationObserver. and binding work with events: https://github.com/fntzr/sirius/blob/master/src/observer.coffee#L144
the framework should provide more good logging for user-space level.
is_log_enabled: bool
log_to: func[level, message, place?]
min_log_level: enum of debug, info, warn, error
is_framework_log_enabled: bool # from sirius core
? more
define event listener for current element:
my_view.for_me
now, for save all models in collection i use array. But for improved performance possible add variant for use any data structure: RBTree, HashTable, or any other. For this, need have interface with base methods: first, takeFirst, collect, map, push, remove...
And use as
MyCollectionWithRedBlackTree = Sirius.Collection.parametrize_for(RedBlackInterface)
my_collection = new MyCollectionWithRedBlackTree(MyModel)
by now, when call Sirius.Application.adapter or logger when logger or adapter yet not defined get error, by it need work like
adapter = Sirius.Application.get_adapter()
adapter.then((adapter) -> ... )
m = new MyModel()
m.bind(v, {
"some selector" : { from: "errors" } # => all errors
"another select" : { from: "errors.title" } # => for title validator
})
Controller =
view: new Sirius.View("...")
method: () ->
model = new MyMode()
view.bind2(model)
Every time, when we call Controller#method
possible memory leak or not?
subj
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.