Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

API for creating views in packages #3752

Closed

Description

@benogle

If we plan to deprecate the space pen View class, we need a story for what folks can move to. Some kind of system that interoperates with custom elements. Something that UI heavy packages like settings view and fnr can use.

  • Maybe it looks like space pen (space-pencil)?
  • Maybe it's react?

We need to do more thinking.

Activity

  1. changed the title [-]View system for packages[/-] [+]API for creating views in packages[/+] on Oct 8, 2014
  2. philipgiuliani commented on Oct 8, 2014

    @philipgiuliani
    Contributor

    Is that really required? What if the packages also would just extend HTMLElements as views? I recently rewrote my package witch HTMLElements instead of using SpacePen and it worked great.

  3. self-assigned this
    on Oct 9, 2014
  4. benogle commented on Oct 27, 2014

    @benogle
    ContributorAuthor

    After discussion and tinkering, we have a direction. The goal is a view system that uses the browser's built in mechanisms as much as possible, embracing new tech like custom elements and Object.observe. Much will be borrowed from Polymer.

    We're encouraging a Model/View approach. Models are just plain objects. e.g. This is a fine model:

    Model = {
      message: 'Find in Buffer'
    }

    A model class:

    class FindModel
      message: 'Find in Buffer'
      constructor: ->

    Views are custom elements with an HTML template. Templates support Polymer's template data-binding.

    We'll provide a registerElement method from a new module called element-kit. It is basically a wrapper around document.registerElement with slightly cleaner syntax.

    Example: Find panel

    screen shot 2014-10-27 at 11 14 15 am

    Model

    class FindModel
      message: 'Find in Buffer'
      constructor: ->
      search: (text) ->
        # do search on current editor

    A custom element view:

    {registerElement} = require 'element-kit'
    
    Template = require('../templates/find.html')
    FindElement = registerElement 'my-find',
      createdCallback: ->
        @appendChild(Template.clone())
        @rootTemplate = @querySelector('template')
        @input = @querySelector('atom-text-editor')
    
        @classList.add 'tool-panel', 'panel-bottom', 'padded'
    
        atom.events.add this, 'button', 'click', -> @confirm()
        atom.events.add this, 'core:confirm', -> @confirm()
    
      confirm: ->
        @model.search(@input.value)
    
      getModel: -> @model
      setModel: (@model) ->
        # setup the data binding
        @rootTemplate?.model = @model

    And the template in ../templates/find.html

    <template bind="{{}}">
      <div>{{message}}</div>
      <div>
        <atom-text-editor mini></atom-text-editor>
        <button class="btn">Search</button>
      </div>
    </template>

    Registration. We need to tie the View to the Model with the view provider system:

    atom.workspace.addViewProvider
      modelConstructor: FindModel
      viewConstructor: FindElement

    Invocation. Create the model, then attach a panel:

    @model = new FindModel
    @panel = atom.workspace.addBottomPanel item: @model
  5. mark-hahn commented on Oct 27, 2014

    @mark-hahn
    Contributor

    Very powerful. It is a shame it is so much more complex.

    On Mon, Oct 27, 2014 at 11:31 AM, Ben Ogle [email protected] wrote:

    After discussion and tinkering, we have a direction. The goal is a
    view system that uses the browser's built in mechanisms as much as
    possible,
    embracing new tech like custom elements and Object.observe. Much will be
    borrowed from Polymer https://www.polymer-project.org.

    We're encouraging a Model/View approach. Models are just plain objects.
    e.g. This is a fine model:

    Model = {
    message: 'Find in Buffer'
    }

    A model class:

    class FindModel
    message: 'Find in Buffer'
    constructor: ->

    Views are custom elements with an HTML template. Templates support
    Polymer's
    template data-binding
    https://www.polymer-project.org/docs/polymer/template.html.

    We'll provide a registerElement method from a new module called
    element-kit.
    It is basically a wrapper around document.registerElement with slightly
    cleaner syntax.
    Example: Find panel

    [image: screen shot 2014-10-27 at 11 14 15 am]
    https://cloud.githubusercontent.com/assets/69169/4796694/32a4d8de-5e05-11e4-87c8-ee25d4b0cd49.png

    Model

    class FindModel
    message: 'Find in Buffer'
    constructor: ->

    A custom element view:

    {registerElement} = require 'element-kit'
    Template = require('../templates/find.html')FindElement = registerElement 'my-find',
    createdCallback: ->
    @appendChild(Template.clone())
    @RootTemplate = @querySelector('template')
    @input = @querySelector('atom-text-editor')

    @classList.add 'tool-panel', 'panel-bottom', 'padded'
    
    atom.events.add this, 'button', 'click', -> @confirm()
    atom.events.add this, 'core:confirm', -> @confirm()
    

    confirm: ->
    getCurrentEditor().scan(@input.value)

    getModel: -> @model
    setModel: (@model) ->
    # setup the data binding
    @RootTemplate?.model = @model

    And the template in ../templates/find.html

    {{message}}
    Search

    Registration. We need to tie the View to the Model with the view provider
    system:

    atom.workspace.addViewProvider
    modelConstructor: CrappyFindModel
    viewConstructor: CrappyFindElement

    Invocation. Create the model, then attach a panel:

    @model = new CrappyFindModel@panel = atom.workspace.addBottomPanel item: @model

    —
    Reply to this email directly or view it on GitHub
    #3752 (comment).

  6. batjko commented on Oct 27, 2014

    @batjko
    Contributor

    I like the resemblance of Polymer in this. Google are pushing that thing pretty badly and it's well thought out to really become big. Also, everything that uses a web components approach is probably the right way forward.

  7. benogle commented on Oct 27, 2014

    @benogle
    ContributorAuthor

    It is a shame it is so much more complex.

    @mark-hahn can you elaborate? There are definitely more distinct entities: a model, a view, a template, and registration. But overall, UIs built with this should be simpler. Data binding will remove a bunch of logic, and the view should have very little logic, just calling things on the model.

  8. mark-hahn commented on Oct 27, 2014

    @mark-hahn
    Contributor

    I was just comparing it my usual spacepen view, object model, and jquery
    binding. If I was building a large app, like Atom itself, the complexity
    would be needed. But most packages are a simple panel at most. Can I still
    use my simple spacepen?

    On Mon, Oct 27, 2014 at 12:33 PM, Ben Ogle [email protected] wrote:

    It is a shame it is so much more complex.

    @mark-hahn https://github.com/mark-hahn can you elaborate? There are
    definitely more distinct entities: a model, a view, a template, and
    registration. But overall, UIs built with this should be simpler. Data
    binding will remove a bunch of logic, and the view should have very little
    logic, just calling things on the model.

    —
    Reply to this email directly or view it on GitHub
    #3752 (comment).

  9. benogle commented on Oct 27, 2014

    @benogle
    ContributorAuthor

    Space pen is going away, so something like this will be the only way.

    2 ways to simplify:

    1. It is possible for us to get rid of the registration step by integrating it with the element registration
    2. you dont need the model if you dont want it. You can insert the view as a panel like this:
    view = document.createElement('my-find')
    @panel = atom.workspace.addBottomPanel item: view
  10. mark-hahn commented on Oct 27, 2014

    @mark-hahn
    Contributor

    It is possible for us to get rid of the registration step

    That would be nice. I noticed in the docs that the state serializer used
    registration at some point in the past. I have just been taking state
    objects in the activate and returning them in serialize and it works
    great. Simplicity is the greatest virtue. :-)

    Space pen is going away

    That's a shame. The barrier to entry for new package developers will
    jump. It's not so much the amount of code but the learning curve. This is
    definitely beyond the skill level of the typical web designer and Atom is
    supposed to be attracting web designers.

    So that means I will have to rewrite the views on my 12 packages. I guess
    that is to be expected since I knew Atom was unstable

    I have but one request. Please think through carefully what benefits
    package writers will get with this new scheme. Don't use the new Chrome
    features because they are cool.

    On Mon, Oct 27, 2014 at 1:55 PM, Ben Ogle [email protected] wrote:

    Space pen is going away, so something like this will be the only way.

    2 ways to simplify:

    1. It is possible for us to get rid of the registration step by
      integrating it with the element registration
    2. you dont need the model if you dont want it. You can insert the
      view as a panel like this: coffee view =
      document.createElement('my-find') @panel = atom.workspace.addBottomPanel
      item: view

    —
    Reply to this email directly or view it on GitHub
    #3752 (comment).

  11. 6 remaining items

  12. mark-hahn commented on Oct 30, 2014

    @mark-hahn
    Contributor

    I have been on a rant and I apologize. I said that this was right for Atom core and now I realize packages have to exactly match core.

    P.S. Separation of concerns has nothing to do with files. Separating html by putting it at the top of the view file is a great separation. To me keeping the view in one file is a great feature. A view is really a kind of single concern when compared to a model.

  13. thomasjo commented on Oct 30, 2014

    @thomasjo
    Contributor

    P.S. Separation of concerns has nothing to do with files. Separating html by putting it at the top of the view file is a great separation. To me keeping the view in one file is a great feature. A view is really a kind of single concern when compared to a model.

    Agreed, but encouraging separate files also encourages the separation of concerns (at least more so than now). That being said, I do still believe you can inline your views if you prefer that approach. Although it will likely not be as "pretty".

  14. nathansobo commented on Oct 30, 2014

    @nathansobo
    Contributor

    We won't be using SpacePen in core, but I see no problem with people continuing to use it if it's a good fit for their packages. We'll need to make a couple slight breaking changes to enable it to keep working in packages without support from core, but the library should continue to work indefinitely.

  15. benogle commented on Oct 30, 2014

    @benogle
    ContributorAuthor

    We've all talked about this and decided 2 things: the injection of globals via polymer isnt something we want to support long term, and it doesnt exactly fit in with the API freeze (it's additive). We plan to revisit this when we're into 1.0 initiative and can spend more time on it.

    For now, @nathansobo is updating space-pen to be forward compatible and used outside of core. We will have a period of time between the freeze and 1.0 where our a recommendation for view code will range from vanilla custom elements to space-pen.

    The stuff I outlined here is at https://github.com/atom/elmer and https://github.com/benogle/template-explore for future reference.

  16. mark-hahn commented on Oct 30, 2014

    @mark-hahn
    Contributor

    @nathansobo https://github.com/nathansobo is updating space-pen to be
    forward compatible and used outside of core.

    Awesome. Thanks.

    On Thu, Oct 30, 2014 at 2:29 PM, Ben Ogle [email protected] wrote:

    We've all talked about this and decided 2 things: the injection of globals
    via polymer isnt something we want to support long term, and it doesnt
    exactly fit in with the API freeze (it's additive). We plan to revisit this
    when we're into 1.0 initiative and can spend more time on it.

    For now, @nathansobo https://github.com/nathansobo is updating
    space-pen to be forward compatible and used outside of core. We will have a
    period of time between the freeze and 1.0 where our a recommendation for
    view code will range from vanilla custom elements to space-pen.

    The stuff I outlined here is at https://github.com/atom/elmer and
    https://github.com/benogle/template-explore for future reference.

    —
    Reply to this email directly or view it on GitHub
    #3752 (comment).

  17. added and removed on Jan 20, 2015
  18. thedaniel commented on Feb 26, 2015

    @thedaniel
    Contributor

    I opened #5756 with a high-level overview of where we're at today and started a list of options. I'm closing this issue in favor of that one, in the interest of starting fresh with the current thinking & requirements.

  19. lock commented on Jan 23, 2019

    @lock

    This issue has been automatically locked since there has not been any recent activity after it was closed. If you can still reproduce this issue in Safe Mode then please open a new issue and fill out the entire issue template to ensure that we have enough information to address your issue. Thanks!

  20. locked as resolved and limited conversation to collaborators on Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions