GithubHelp home page GithubHelp logo

Comments (18)

kentcdodds avatar kentcdodds commented on August 28, 2024

One thing that we could do is do a replace on the template strings if the symbols are none-standard. This should be relatively trivial and might be a good first timer issue to...

from angular-formly-templates-bootstrap.

davidlukerice avatar davidlukerice commented on August 28, 2024

Good idea. I'm assuming that would be a change in angular-formly and not in the template repos?

from angular-formly-templates-bootstrap.

kentcdodds avatar kentcdodds commented on August 28, 2024

Actually, no, this would happen in this repo. Anywhere we require a
template, we'd do a replace.

On Wed, Sep 30, 2015, 2:27 PM David Rice [email protected] wrote:

Good idea. I'm assuming that would be a change in angular-formly
https://github.com/formly-js/angular-formly and not in the template
repos?


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

from angular-formly-templates-bootstrap.

davidlukerice avatar davidlukerice commented on August 28, 2024

Seems a bit redundant to have to do it each time a template gets required. I'm currently just using

.run([ '$interpolate', 'formlyConfig', function($interpolate, formlyConfig) {
        formlyConfig.templateManipulators.postWrapper.push(function(template, options, scope) {
            return template.replace(/{{/g, $interpolate.startSymbol())
                           .replace(/}}/g, $interpolate.endSymbol());
        });
    }])

when I initialize my own app to get around the issue, so was assuming I could do something similar in angular-formly. Unless there's some performance hit that I'm not seeing.

from angular-formly-templates-bootstrap.

kentcdodds avatar kentcdodds commented on August 28, 2024

That's not what I mean. What I mean is, anywhere we do this:

template: require('./label.html'),

We change it to:

template: fixInterpolationSymbols(require('./label.html'), $interpolate),

where fixInterpolationSymbols is something like this:

function fixInterpolationSymbols(templateString, $interpolate) {
  var start = $interpolate.startSymbol();
  var end =  $interpolate.endSymbol();
  if (start !== '{{') {
    templateString = templateString.replace(/{{/g, start);
  }
  if (end !== '}}') {
    templateString = templateString.replace(/}}/g, end);
  }
  return templateString;
}

from angular-formly-templates-bootstrap.

kentcdodds avatar kentcdodds commented on August 28, 2024

We'd put that function in a regular ES6 module and import it where we need it (hence it needs to accept the $interpolate as an additional argument).

from angular-formly-templates-bootstrap.

davidlukerice avatar davidlukerice commented on August 28, 2024

The import method still requires a code change every place a template is required, right (so 5 places in angular-formly-templates-bootstrap)? The module would also need to be duplicated across each angular-formly-templates-* repo and its template requires changed. This leaves quite a bit of room for bugs to slip in if a dev forgets to apply the fix method on a template import or if the method is updated in one template repo and not another. I understand the desire to leave templating concerns in the template extensions, but that much duplication makes me think the fix is at the wrong abstraction layer.

This is opposed to just having the single postWrapper push in say angular-formly/src/run/updateInterpolateSymbols.js.

export default updateInterpolateSymbols;

// @ngInject
function updateInterpolateSymbols(formlyConfig, $interpolate) {
  formlyConfig.templateManipulators.postWrapper.push(updateSymbols);

  function updateSymbols(template, options, scope) {
    var start = $interpolate.startSymbol();
    var end =  $interpolate.endSymbol();
    if (start !== '{{') {
      templateString = templateString.replace(/{{/g, start);
    }
    if (end !== '}}') {
      templateString = templateString.replace(/}}/g, end);
    }
    return templateString;
  }
}

The postWrapper seems designed for this sort of thing and looks like replacements would be more efficient, being called only once per form instead of once per template require.

from angular-formly-templates-bootstrap.

kentcdodds avatar kentcdodds commented on August 28, 2024

That makes sense. One issue I can see is that this will run for every field for every compile. While it's nice that you ensure you cover all the bases, it's sub-optimal from a perf standpoint. But that may be negligible.

That said, I don't want to put that in angular-formly core. A very small percentage of formly users will need it. But a plugin for that would be fantastic. Would you be interested in creating a plugin for that? See here for more info.

from angular-formly-templates-bootstrap.

davidlukerice avatar davidlukerice commented on August 28, 2024

Oh, yah, that linking call is on the field and not the whole form. Makes sense to not want it in core. I can definitely throw it in a plugin.

from angular-formly-templates-bootstrap.

davidlukerice avatar davidlukerice commented on August 28, 2024

Would you prefer the angular-formly-dynamic-interpolate-symbols plugin to reside in the formly-js org?

from angular-formly-templates-bootstrap.

kentcdodds avatar kentcdodds commented on August 28, 2024

I'll let you decide. I'll happily create the repo and add you as a collaborator if you like :-)

from angular-formly-templates-bootstrap.

davidlukerice avatar davidlukerice commented on August 28, 2024

Sure, that works for me. I'm assuming I can just mimic the structure of an existing plugin?

from angular-formly-templates-bootstrap.

kentcdodds avatar kentcdodds commented on August 28, 2024

Here's the repo: https://github.com/formly-js/angular-formly-dynamic-interpolate-symbols, you've been invited to collaborate on it.

You can feel free to do whatever you like with regards to the plugin. I don't recommend you go with the kcd-common-tools approach like some of the other plugins. It's a bit complex and not fully baked.

Feel free to do it however you like. Personally, I recommend you checkout my How to Write an Open Source JavaScript Library series on egghead, and then combine that knowledge with Webpack (egghead.io playlist).

Sorry that the original series isn't quite to webpack yet. Though you should be able to get away with doing this in a single file... If you want to DM me on twitter, I can give you access to a private video which could help you out as well..

from angular-formly-templates-bootstrap.

kentcdodds avatar kentcdodds commented on August 28, 2024

Oh, my twitter is: https://twitter.com/kentcdodds

from angular-formly-templates-bootstrap.

davidlukerice avatar davidlukerice commented on August 28, 2024

Alright, this feature is now in https://github.com/formly-js/angular-formly-dynamic-interpolate-symbols.

from angular-formly-templates-bootstrap.

kentcdodds avatar kentcdodds commented on August 28, 2024

This is terrific! I'll add it to the plugins page. Could you make an example for the website?

from angular-formly-templates-bootstrap.

kentcdodds avatar kentcdodds commented on August 28, 2024

Added

from angular-formly-templates-bootstrap.

davidlukerice avatar davidlukerice commented on August 28, 2024

Alright. Put in a PR to add an example to the advanced tab.
formly-js/angular-formly-website#81

from angular-formly-templates-bootstrap.

Related Issues (20)

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.