Giter Club home page Giter Club logo

sirius's People

Contributors

fntz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sirius's Issues

property binding for models

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: '', ...}
)

method for create javascript model classes

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() {} 
})

add sirius-core

sirius-core include only routing support (with logger of course) without models, views, and another parts of framework

composition for models

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

collection index

   class MyModel extends Sirius.BaseModel
     @attrs: ["id", "firstName", "secondName"]

   myCollection = new Sirius.Collection(MyModel, [], {
     index: ["id", "firstName"]
   })

view.zoom

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>

skip field

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.

binding redesign

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     
   }
) 

Why ?

Because View should know nothing about Model, and the same still valid for Model

Requirements:

  1. Generate default binding i.e. i do not want write every time how to transform text field into text attribute for Model

  2. New Logger name: Transformer

  3. I think need add some validation: check that all html elements are present in View, and check that all attributes are present in model

Q?

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

reset attributes for model

# 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

model versioning

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



bug in route

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"

add scheduler in route

route = {
   "scheduler 1s 10s" : controller: MyScheduler, action: every_10s
   "once 1s 10s": controller: MyScheduler, ction: once_10s
}

# 1s - wait
# 10s - every 

provide log source

# instead of 
Sirius.Application.get_logger()

# transform to
Sirius.Application.get_logger("class_name")

# and tranform log to 

[LEVEL] [SOURCE] [Message]

q?

log_format ?

redirect bug

when we call redirect method: redirect("/path") it not call url function for it.

recursion detect

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

cache for View

new Sirius.View must return already create view, if it created.

controllers wrapper

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)

[draft] new materializers/bindings

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

  1. view to model
  2. model to view
  3. view to view
  4. model/view to function

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

[draft] to_view convert

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()

better logging.

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 
  • add min log level
  • rename log options
  • tests should be included

collection parametrize

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)

logger, adapter should be async

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) -> ... )

binding for all errors

m = new MyModel()
m.bind(v, {
  "some selector" : { from: "errors" }  # => all errors 
  "another select" : { from: "errors.title" } # => for title validator
})

possible memory leak

Controller =
   view: new Sirius.View("...")

   method: () ->
      model = new MyMode()
      view.bind2(model)

Every time, when we call Controller#method possible memory leak or not?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.